l = int(input()) n = int(input()) w_lst = list(map(int, input().split(' '))) w_lst.sort(reverse=False) sum = 0 cnt = 0 for w in w_lst: sum += w if sum <= l: cnt += 1 else: break print(cnt)