T = list(map(int, input().split())) nokori = 6000 for t in T: if t == -1: nokori = -1 else: nokori -= t if nokori >= 0: print(nokori) else: print(-1)