Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.

Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.

Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?


-----Input-----

The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).


-----Output-----

If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam. 

If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.


-----Examples-----
Input
10 10 5 20

Output
5
Input
2 2 0 4

Output
-1
Input
2 2 2 1

Output
-1


-----Note-----

The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.

In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.

The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible.

Difficulty: interview

Starter code:

Solutions:
a,b,c,n=list(map(int,input().split()))
x=a+b-c
print(n-x if c<=a and c<=b and x<n else -1)


a,b,c,n = list(map(int, input().split()))
if c > a or c > b or n- (a+b-c) < 1:
    print(-1)
else:
    print(n- (a+b-c))


a, b, c, n = list(map(int, input().split()))
rem = n - (a + b - c)
if (rem < 1 or c > a or c > b):
	print(-1)
else:
	print(rem)


a,b,c,n=list(map(int,input().split()))
if (c > a or c > b or a + b - c > n - 1):
  print(-1)
else:
  print(n-a-b+c)


a, b, c, n = map(int, input().split())
ans = n - a - b + c
if (ans < 1) or (min(a, b) < c):
    print(-1)
else:
    print(ans)

from sys import stdin, stdout

a, b, c, d = map(int, stdin.readline().split())
q = d - a - b + c

if c > min(a, b) or q <= 0:
    stdout.write('-1')
else:
    stdout.write(str(q))

def read_input():
	return map(int, input().split())

a, b, c, n = read_input()
only_a, only_b = a - c, b - c
if only_a < 0 or only_b < 0:
	print(-1)
	return
total = only_b + only_a + c
if total >= n:
	print(-1)
	return
print(n - only_a - only_b - c)

a, b, c, n = list(map(int, input().split()))
x = n - (a + b - c)
a -= c
b -= c

if x <= 0 or a < 0 or b < 0:
    print(-1)
else:
    print(x)


a,b,c,n=(map(int,input().strip().split(' ')))
if(a+b-c>=n or a>=n or b>=n or c>=n):
  print(-1)
elif(c>min(a,b)):
  print(-1)
else:
  print(n-a-b+c)

a, b, c, n = list(map(int, input().strip().split()))

a -= c
b -= c

if a < 0 or b < 0 or a + b + c > n - 1:
    print('-1')
else:
    print(n - a - b - c)


a,b,c,n=list(map(int,input().split()))
result=n-(a+b-c)
if result<=0 or c>a or c>b or a>n or b>n:
    print(-1)
else:
    print(result)



a, b, c, n = list(map(int, input().split()))

passed = a + b - c

if c > a or c > b or passed > n - 1:
    print(-1)
else:
    print(n - passed)



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time


(A, B, C, N) = (int(i) for i in input().split())

start = time.time()

ans = N+C-A-B
if (ans <= 0) or (C>A) or (C>B):
    ans = -1

print(ans)
finish = time.time()
#print(finish - start)


a, b, c, n = map(int, input().split())
if a + b - c >= n:
	print(-1)
elif a < c or b < c:
	print(-1)
else:
	print( n - (a + b - c))

#!/usr/bin/env python3
A, B, C , N = [int(i) for i in input().split()]
count = A + B - C
if C > A or C > B:
    print(-1)
elif count < 0:
    print(-1)
elif count >= N:
    print(-1)
else:
    print(N - count)


# 
#      ___           ___                       ___       ___           ___       ___     
#     /\__\         /\  \          ___        /\__\     /\  \         /\__\     /\  \    
#    /:/  /        /::\  \        /\  \      /:/  /    /::\  \       /:/  /    /::\  \   
#   /:/__/        /:/\:\  \       \:\  \    /:/  /    /:/\:\  \     /:/  /    /:/\ \  \  
#  /::\__\____   /::\ˉ\:\  \      /::\__\  /:/  /    /:/  \:\__\   /:/  /    _\:\ˉ\ \  \ 
# /:/\:::::\__\ /:/\:\ \:\__\  __/:/\/__/ /:/__/    /:/__/ \:|__| /:/__/    /\ \:\ \ \__\
# \/_|:|ˉˉ|ˉ    \/__\:\/:/  / /\/:/  /    \:\  \    \:\  \ /:/  / \:\  \    \:\ \:\ \/__/
#    |:|  |          \::/  /  \::/__/      \:\  \    \:\  /:/  /   \:\  \    \:\ \:\__\  
#    |:|  |          /:/  /    \:\__\       \:\  \    \:\/:/  /     \:\  \    \:\/:/  /  
#    |:|  |         /:/  /      \/__/        \:\__\    \::/__/       \:\__\    \::/  /   
#     \|__|         \/__/                     \/__/     ˉˉ            \/__/     \/__/    
#

a, b, c, n = list(map(int, input().split()))
if c > a or c > b:
    print(-1)
    return
ans = n-(a+b-c)
if ans > 0:
    print(ans)
else:
    print(-1)


a, b, c, n = [int(item) for item in input().split()]

if a + b - c > n - 1 or c > min(a, b):
    print(-1)
else:
    print(n - a - b + c)


a,b,c,n=list(map(int,input().split()))
if c <= min(a,b) and max(a,b) < n and n-a-b+c >=1:
    print(n-a-b+c)
else:
    print(-1)


query = list(map(int,input().split()))

total = query[3]

sdali = query[0]+query[1]-query[2]
if query[2]>query[1] or query[2]>query[0]:
    print(-1)
elif sdali>total:
    print(-1)
else:
    nesdali = total-sdali
    if nesdali<1:
        print(-1)
    else:
        print(nesdali)

3

def solve(A, B, C, N):
    if C > A or C > B:
        return -1

    if A + B - C > N:
        return -1

    rest = N - (A + B - C)
    if rest == 0:
        return -1

    return rest


def main():
    A, B, C, N = [int(e) for e in input().split(' ')]

    print(solve(A, B, C, N))


def __starting_point():
    main()

__starting_point()

A, B, C, N = [int(i) for i in input().split()]
summ = A - C + B
if summ >= N or (C > min(A, B)):
	print(-1)
else:
	print(N - summ)

#JMD
#Nagendra Jha-4096
 
#a=list(map(int,sys.stdin.readline().split(' ')))
#n,k,s= map(int, sys.stdin.readline().split(' '))
 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
a,b,c,n= map(int, sys.stdin.readline().split(' '))
if(a<=n and  b<=n and c<=a and c<=b and (a+b-c)<n):
    print(n-a-b+c)
else:
    print(-1)
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

a, b, c, n = list(map(int, input().split()))

ans = n - (a + b - c)
if ans < 1 or c > a or c > b or a > n or b > n or c > n:
    print(-1)
else:
    print(ans)


a, b, c, n = [int(i) for i in input().split()]
k = n - a - b + c
if k < 1 or c > min(a, b) or c > n:
    print(-1)
else:
    print(k)