L = int(input()) _ = int(input()) Ws = list(map(int, input().split(' '))) Ws.sort() s = 0 for i, W in enumerate(Ws): s = s + W if s <= L: pass else: print(i) break else: print(i+1)