L = int(input()) n = int(input()) blocks = sorted(list(map(int,input().split()))) cnt = 0 for block in blocks: L -= block cnt += 1 if L <= 0: break if L < 0: print(cnt - 1) else: print(cnt)