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