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