import java.io.*; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main (String[] args) throws IOException { Scanner sc = new Scanner(System.in); int L = sc.nextInt(); int N = sc.nextInt(); int W[] = new int [N]; for (int i = 0 ; i <= N-1 ; i++){ W[i] = sc.nextInt(); } Arrays.sort(W); int sum = 0; int ans = 0; for (int j = 0; sum + W[j] <= L ; j++){ ans = ans + 1; sum = sum + W[j]; } System.out.println(ans); } }