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