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