L = input() N = input() W = map(int,raw_input().split(" ")) W.sort() ans = 0 cnt = 0 for w in W: cnt += w if cnt > L: break ans += 1 print ans