L = int(input()) N = int(input()) W = list(map(int,input().split())) num = 0 W.sort() while(True): L -= W[num] if(L >= 0): num += 1 continue break print(num)