*x,=map(int,input().split()) for i in range(7): if any(z == -1 for z in x[:i+1]): print(-1) else: print(max(-1, 6000-sum(x[:i+1])))