import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int max = Integer.parseInt(br.readLine()); int nums = Integer.parseInt(br.readLine()); String params[] = br.readLine().split(" "); ArrayList list = new ArrayList(); for (int i = 0; i < nums; i++) { list.add(Integer.parseInt(params[i])); } Collections.sort(list); int min = max; for (int i = list.size() - 1; i >= 0; i--) { int tmpNum = max; int tmpCount = 0; for (int j = i; j >= 0; j--) { while (true) { if (tmpNum >= list.get(j)) { tmpNum = tmpNum - list.get(j); tmpCount++; } else { break; } } } if (tmpNum == 0 && min > tmpCount) { min = tmpCount; } } if (min != max) { System.out.println(min); return; } System.out.println(-1); } }