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