L = int(input()) N = int(input()) W = map(int, input().split(' ')) sort_w = sorted(W) count = 0 total = 0 for w in sort_w: if L > total + w: total = total + w count = count + 1 else: break print(count)