l = int(input()) n = int(input()) w_ls = list(map(int, input().split())) w_ls.sort() ct = 0 for w in w_ls: if l < w: break l -= w ct += 1 print(ct)