L = int(input()) N = int(input()) W = sorted(map(int, input().split())) cnt = 0 while sum(W) > L: W.pop() cnt += 1 print(cnt)