from tkinter import W from traceback import print_tb L = int(input()) N = int(input()) W_list = list(map(int, input().split())) count = 0 W_list.sort() for w in W_list: if(L < w): break L -= w count += 1 print(count)