L = int(input()) N = int(input()) W = list(map(int, input().spled())) sort(W) s = 0 for i in range(N): if L >= W[i]: s = s + 1 L = L - W[i] print(s)