l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() max = 0 ww = 0 for a in w: ww += a if ww <= l: max += 1 else: break print(max)