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: box = box + s count = count + 1 if box == num: break elif box >= num: count = count - 1 break print(count)