import numpy as np l = int(input()) n = int(input()) w = sorted(list(map(int,input().split()))) cumsum = np.cumsum(w) ret = 0 for c in cumsum: if c > l: break ret += 1 print(ret)