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