LIMIT = 6000 T = [int(s) for s in input().split()] sum_val = 0 for t in T: sum_val += t ans = LIMIT - sum_val print(ans if ans >= 0 else -1)