L = int(input()) N = int(input()) W = sorted(list(map(int,input().split()))) c = 0 ans = 0 for i in range(N): if L >= c+W[i]: c += W[i] ans += 1 print(ans)