l = int(input()) n = int(input()) ans = 0 cnt = 0 for w in sorted(map(int, input().split())): if w + ans > l: break ans += w cnt += 1 print(cnt)