a=list(map(int,input().split())) ans=[] now=6000 for i in range(len(A)): if A[i]==-1: A[i]=1000000 now-=A[i] print(max(now,-1))