L = int(input()) N = int(input()) boxes = list(map(int, input().split())) boxes.sort() count = 0 for b in boxes: L -= b if L >= 0: count += 1 else: break print(count)