l = int(input()) n = int(input()) W = sorted(list(map(int,input().split()))) now = 0 for i,w in enumerate(W): now += w if now > l: print(i) exit() print(n)