L = int(input()) N = input() lst = list(map(int, input().split())) lst_sorted = sorted(lst) Sum = 0 score = 0 for i in lst_sorted: if L >= Sum + i: Sum += i score += 1 else: print(score) break