L = input() N = input() W = map(int, raw_input().split()) W.sort() count = 0 for i in xrange(N): L -= W[i] if L < 0: break count += 1 print count