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) break elif w == box: print(n + 1) break else: print(num)