L = int(input()) N = int(input()) W = sorted(list(map(int, input().split()))) SW = sum(W) while SW > L: SW -= W[N - 1] N -= 1 W.pop() print(len(W))