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: break cnt -= 1 print(cnt)