L = int(input().strip()) N = int(input().strip()) W = [int(i) for i in input().strip().split(' ')] W = sorted(W) s = 0 c = 0 for i in W: s += i if s > L: break c += 1 print(c)