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