L, N = int(input()), int(input()) W_list = list(map(int, input().split())) W_list = sorted(W_list) if L >= sum(W_list): print(N) exit() sumsum = 0 for i in range(N): if sumsum + W_list[i] < L: sumsum += W_list[i] continue elif sumsum + W_list[i] == L: print(i + 1) exit() else: print(i if i != 0 else '0') exit()