L = int(input()) N = int(input()) W = [int(i) for i in input().split()] W.sort() LL = 0 ans = 0 while LL <= L: LL += W.pop(0) ans += 1 print(ans-1)