import java.util.*; class NumBlocks { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int l = sc.nextInt(); int n = sc.nextInt(); int[] intWi = new int[n]; for (int i = 0; i < n; i++) { intWi[i] = sc.nextInt(); } Arrays.sort(intWi); int result = 0; for (int i = 0; i < n; i++) { l -= intWi[i]; if (0 <= l) result++; } System.out.println(result); } }