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