L = int(input()) N = int(input()) W = input().split() W.sort(key=int) l=0 c=0 for i in range(N): l += int(W[i]) if l > L: break c = i + 1 print(c)