box = int(input()) num = int(input()) widths = list(map(int, input().split())) widths.sort() w = 0 for n, width in enumerate(widths): w += width if w > box: print(n) exit() elif w == box: print(n+1) exit() print(num)