T = list(map(int, input().split())) total = 6000 ng = False for i in range(len(T)): if ng: print(-1) continue if T[i] == -1: ng = True print(-1) continue total -= T[i] if 0 <= total: print(total) else: print(-1)