L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() now = 0 ans = 0 for i in range(N): now += W[i] if now<=L: ans = max(ans, i+1) print(ans)