L = int(input()) N = int(input()) W = sorted(list(map(int,input().split()))) for i in range(1, len(W)+1): L = L - W[i] if L < 0: break print(i)