# これは嘘解法です t = list(map(int, input().split(' '))) now = 6000 for i in range(7): if t[i] != -1: now -= t[i] if now < 0: print(-1) else: print(now) else: print(-1)