l = int(input()) n = int(input()) w = [int(i) for i in input().split()] w.sort() s = 0 res = 0 for i in w: if l >= s + i: s += i res += 1 else: break print(res)