L = int(input()) N = int(input()) W = list(map(int, input().split())) ww = [] i = 0 while True: if W != []: w = min(W) W.remove(w) ww.append(w) i += 1 else: break if sum(ww) <= L: continue else: break print(i)