import java.io.*; import java.util.*; public class Main { static ArrayList> dp = new ArrayList<>(); static ArrayList list = new ArrayList<>(); static int[] sums; static int[] times; static int full; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int t = sc.nextInt(); int n = sc.nextInt(); full = (1 << n) - 1; times = new int[n]; for (int i = 0; i < n; i++) { times[i] = sc.nextInt(); } Arrays.sort(times); sums = new int[n]; sums[0] = times[0]; for (int i = 1; i < n; i++) { sums[i] = sums[i - 1] + times[i]; } make(n - 1, t, 0); for (int i = 0; i < list.size(); i++) { dp.add(new HashMap<>()); } System.out.println(dfw(list.size() - 1, 0)); } static int dfw(int idx, int mask) { if (mask == full) { return 0; } if (idx < 0) { return Integer.MAX_VALUE / 2; } if (!dp.get(idx).containsKey(mask)) { int value = dfw(idx - 1, mask); if ((mask & list.get(idx)) != list.get(idx)) { value = Math.min(value, dfw(idx - 1, mask | list.get(idx)) + 1); } dp.get(idx).put(mask, value); } return dp.get(idx).get(mask); } static void make(int idx, int remain, int value) { if (idx < 0) { list.add(value); return; } value <<= 1; if (remain < times[idx]) { make(idx - 1, remain, value); } else if (remain >= sums[idx]) { make(idx - 1, remain - times[idx], value + 1); } else { make(idx - 1, remain, value); make(idx - 1, remain - times[idx], value + 1); } } static long getCount(long x, long n) { if (x == 1 || x > 2 * n) { return 0; } else if (x <= n) { return x - 1; } else { return n - (x - n) + 1; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }