import java.util.*; class Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int L = sc.nextInt(); int N = sc.nextInt(); int a[] = new int[N]; int cnt = 0; for(int i = 0; i < N; i++){ a[i] = sc.nextInt(); } Arrays.sort(a); for(int j:a){ L -= j; if(L < 0) break; cnt++; } System.out.println(cnt); } }