import java.util.*; import java.io.*; public class Main { static int[] dp; 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) { 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 i = (key - 1) & key; i > 0; i = (i - 1) & key) { min = Math.min(min, dfw(i) + dfw(key ^ i)); if (min == 2) { break; } } dp[key] = min; return min; } }