L = int(input()) N = int(input()) W = list(map(int,input().split())) W.sort() now = 0 S = 0 while now < N: if S + W[now] <= L: S += W[now] now += 1 else: break print(now)