L = int(input()) N = input() blocks = list(map(int, input().split())) s_blocks = sorted(blocks) width = 0 for i , block in enumerate(s_blocks) : if L >= width + block : width += block else : print(i) break else : print(len(s_blocks))