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