L = int(input()) N = int(input()) W = list(map(int,input().split())) sorted_W = sorted(W) sum_wide = 0 ans = 0 while True: if sum_wide + sorted_W[ans] > L: break sum_wide += sorted_W[ans] ans += 1 print(ans)