L = int(input()) N = int(input()) W = list(map(int,input().split())) W_sorted = sorted(W) s = 0 for i in W_sorted: if L >= i: L = L - i s = s + 1 print(s)