def main(): L = int(input()) N = int(input()) W = list(map(int,(input().split()))) W.sort() #print(L, N, W) blocks = 0 for i in W: if i <= L: blocks = blocks + 1 L = L - i print(blocks) if __name__ == '__main__': main()