L = int(input()) N = int(input()) a = [int(x) for x in input().split()] b = sorted(a) temp = 0 c = 0 for i in range(N): temp += b[i] if temp == L: print(i + 1) c = 1 break elif temp > L: print(i) c = 1 break if c == 0: print(N)