L = input() N = input() W = map(int, raw_input().split()) W.sort() count = 0 for i in W: L -= i if L >= 0: count += 1 print count