import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int sum = 0; int count = 0; int L = scanner.nextInt(); int N = scanner.nextInt(); int a[] = new int[N]; for(int i = 0;i < N;i++){ a[i] = scanner.nextInt(); } Arrays.sort(a); for(int i = 0;i < N;i++){ sum += a[count]; count++; if(sum>L){ break; } } if(sum>L){ count -= 1; } System.out.println(count); scanner.close(); } }