l = int(input()) n = int(input()) w = list(map(int, input().split())) ans = 0 box = 0 sort_w = sorted(w) for i in sort_w: if box <= l - i: box += i ans += 1 else: break print(ans)