Tli = list(map(int, input().split())) t = 0 f = True for i in Tli: if i == -1: f = False t += i if f and t <=6000: print(6000 - t) else: print(-1)