import java.util.*; import java.io.*; public class Main { static int[] dp; static HashSet ones = new HashSet<>(); public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); int n = Integer.parseInt(br.readLine()); int[] times = new int[n]; for (int i = 0; i < n; i++) { times[i] = Integer.parseInt(br.readLine()); } dp = new int[1 << n]; for (int i = 1; i < (1 << n); i++) { int sum = 0; for (int j = 0; j < n; j++) { if ((i & (1 << j)) == 0) { continue; } sum += times[j]; if (sum > t) { break; } } if (sum <= t) { ones.add(i); dp[i] = 1; } } System.out.println(dfw((1 << n) - 1)); } static int dfw(int key) { if (key == 0) { return 0; } if (dp[key] != 0) { return dp[key]; } int min = Integer.MAX_VALUE; for (int x : ones) { if ((x & key) != x) { continue; } min = Math.min(min, dfw(x ^ key) + 1); if (min == 2) { break; } } dp[key] = min; return min; } }