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