L = int(input()) N = int(input()) W_list = list(map(int, input().split())) # L:箱の幅, N:ブロック数, W: ブロックの幅 W_list.sort() count = 0 box_surplus = L for w in W_list: if box_surplus >= w: box_surplus -= w count += 1 else: break print(count)