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) else: i += 1 break if sum(ww) <= L: continue else: break if i != 1: print(len(ww)-1) else: print(len(ww))