l = int(input()) n = int(input()) w = sorted(list(map(int,input().split()))) s = 0 res = 0 for i in w: res += 1 s += i if s>l: print(res-1) exit()