import math a = int(input()) b = int(input()) c = list(map(int, input().split())) c.sort() d = 0 e = 0 for i in range(b): d += c[i] if d > a: break e += 1 print(e)