L = int(input()) N = int(input()) Wn = list(map(int, input().split())) Wn.sort() ans= 0 for i in Wn: if L >= i: L -= i ans += 1 print(ans)