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