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