L = int(input()) N = int(input()) w = list(map(int, input().split())) w = sorted(w) cnt = 0 for j in w: L = L - j cnt += 1 if L < 0: cnt -= 1 break print(cnt)