N, M = 7, 6000 A = list(map(int,input().split())) for i in range(N): if A[i] == -1: M = -1 else: M -= A[i]; print(M if M >= 0 else -1)