l = int(input()) n = int(input()) a = list(map(int,input().split())) a = sorted(a) res = 0 for i in a: if i <= l: res += 1 l -= i print(res)