l = int(input()) input() w = list(map(int,input().split())) w.sort() count = 0 for i in w: if l < i: break count += 1 l -= i print(count)