l = int(input()) n = int(input()) w = list(map(int,input().split())) w = sorted(w) num = 0 ans = 0 for i in w: num += i if num > l: break ans += 1 print(ans)