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