A = tuple(map(int, input().split())) T = 6000 for a in A: T -= a if a != -1 else 10000 if T >= 0: print(T) else: print(-1)