l = int(input()) n = int(input()) w = sorted(list(map(int, input().split()))) ans = 0 for i in w: if i <= l: ans += 1 l -= i print(ans)