inp1 = input() inp_dust = input() inp2 = input().split() seq= [] for s in inp2: seq.append(int(s)) seq = sorted(seq) num = int(inp1) box = 0 count = 0 for s in seq: if box >= num: break box = box + s count = count + 1 count = count -1 print(count)