L = int(input()) N = int(input()) W_LIST = list(map(int, input().split())) W_LIST.sort() w = 0 a = 0 for i in range(N): if (w + W_LIST[i]) >= L: print(a) break else: w+=W_LIST[i] a+=1