import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int c = Integer.parseInt(br.readLine()); int n = Integer.parseInt(br.readLine()); int[] values = new int[n]; String[] line = br.readLine().split(" ", n); for (int i = 0; i < n; i++) { values[i] = Integer.parseInt(line[i]); } Arrays.sort(values); int[] maxes = new int[c + 1]; Arrays.fill(maxes, Integer.MAX_VALUE); TreeSet next = new TreeSet<>(); next.add(0); maxes[0] = 0; while (next.size() > 0) { int i = next.pollFirst(); for (int j = 0; j < n && i + values[j] <= c; j++) { maxes[i + values[j]] = Math.min(maxes[i + values[j]], maxes[i] + 1); next.add(i + values[j]); } } if (maxes[c] == Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(maxes[c]); } } }