L = int(input()) N = int(input()) M = sorted(list(map(int,input().split()))) i = 0 while True: L -= M[i] if(L <= 0): print(i) break else: i+=1