l = int(input()) n = int(input()) a = list(map(int,input().split())) a.sort() tot = 0 for i in range(n): tot += a[i] if tot > l: print(i) exit() print(n)