from itertools import accumulate l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() a = list(accumulate(w)) for i in range(n): if l < a[i]: print(i) exit() print(n)