remain=6000 now=0 A=list(map(int,input().split())) for i in range(len(A)): now+=A[i] print(remain-now if remain>=now else -1)