sm = 0 for x in map(int, input().split()): if x != -1 and sm != -1: sm += x else: sm = -1 print(6000 - sm if 0 <= sm <= 6000 else -1)