L = int(input()) N = int(input()) Ws = list(map(int, input().split())) Ws.sort() tmp = 0 for i, w in enumerate(Ws): if L >= tmp + w: tmp += w else: print(i) break else: print(len(Ws))