import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); try { int L = Integer.parseInt(read.readLine()); int N = Integer.parseInt(read.readLine()); String[] box = read.readLine().split(" "); int[] w = new int[N]; for (int i = 0; i < N; ++i) { w[i] = Integer.parseInt(box[i]); } int total = 0, ans = 0; for (int i = 0; i < N - 1; ++i) { for (int j = i + 1; j < N; ++j) { if (w[i] > w[j]) { int sw = w[i]; w[i] = w[j]; w[j] = sw; } } total += w[i]; if (total <= L) { ++ans; } else { break; } } System.out.println(ans); } catch (Exception e) { e.printStackTrace(); } } }