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: EASY

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


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


import sys
import collections
import itertools as it

def readArray(type=int):
	line = input()
	return [type(x) for x in line.split()]

def getFreq(arr):
	freq = collections.defaultdict(int)
	for x in arr:
		freq[x] += 1
	return freq

def solve():
	(a, b, c, n) = readArray()
	total = a + b - c
	cc = 0
	if c > a or c > b:
		cc = -1
	elif total < 0:
		cc = -1
	elif total > n - 1:
		cc = -1
	else:
		cc = n - total
	print(cc)
solve()


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


(n, p, i, r) = list(map(int, input().split()))
pa = n - i
la = p - i
if pa + la + i < r and pa >= 0 and (la >= 0):
	print(r - (pa + la + i))
else:
	print('-1')


(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)


import math
getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
(a, b, c, n) = getInputIntList()
if a - c > -1 and b - c > -1 and (n - (a - c + (b - c)) - c > 0):
	print(n - (a - c + (b - c)) - c)
else:
	print(-1)


(A, B, C, N) = list(map(int, input().split()))
res = N - (A + B - C)
if res >= 1 and min(A, B) >= C:
	print(res)
else:
	print(-1)


(a, b, c, n) = 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, d) = map(int, input().split())
print(*([-1] if a < c or b < c or a + b - c >= d else [d - (a + b - c)]))


n = list(map(int, input().split()))
s = n[0] - n[2]
v = n[1] - n[2]
w = n[3] - (s + v + n[2])
if w == 0 or s < 0 or v < 0 or (w < 0):
	print('-1')
elif w > n[3]:
	print(-1)
else:
	print(w)


l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
n = int(l[3])
if n - a - b + c >= 1:
	if a >= c and b >= c:
		if n > a and n > b:
			print(n - a - b + c)
		else:
			print('-1')
	else:
		print('-1')
else:
	print('-1')


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


(a, b, c, n) = map(int, input().split())
p = a + b - c
f = n - p
if p < n and f >= 1 and (a >= c) and (b >= c):
	print(f)
	exit()
print(-1)


(a, b, c, n) = [int(x) for x in input().strip().split(' ')]
v = n - a - b + c
if v > 0 and c <= a and (c <= b):
	print(v)
else:
	print(-1)


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


TN = 1

def solution():
	(a, b, c, n) = map(int, input().split())
	if c > a or c > b:
		ans = -1
	elif n - (a - c + b) <= 0:
		ans = -1
	else:
		ans = n - (a - c + b)
	print(ans)
while TN != 0:
	solution()
	TN -= 1


(A, B, C, N) = map(int, input().split())
r = N - (A + B - C)
if r >= 1 and C <= A and (C <= B):
	print(r)
else:
	print(-1)


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


(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) = map(int, input().strip().split())
D = N - (A + B - C)
if D <= 0 or C > A or C > B:
	print('-1')
	exit(0)
print(D)


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


import sys
(a, b, c, d) = map(int, sys.stdin.readline().split())
if a + b - c >= d or a >= d or b >= d or (c >= d) or (c > a) or (c > b):
	print(-1)
else:
	print(d - (a + b - c))


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


t = input().strip().split(' ')
t = [int(e) for e in t]
A = t[0]
B = t[1]
C = t[2]
N = t[3]

def haha():
	x = N - (A + B - C)
	if A < C:
		return -1
	if B < C:
		return -1
	if x < 1:
		return -1
	return x
print(haha())


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


(A, B, C, N) = map(int, input().split())
ans = N - A - B + C
if A < C:
	print(-1)
elif B < C:
	print(-1)
elif ans <= 0:
	print(-1)
else:
	print(ans)


__author__ = 'Esfandiar'
(A, B, C, N) = map(int, input().split())
A -= C
B -= C
if A >= 0 and B >= 0 and (A + B + C < N):
	print(N - (A + B + C))
else:
	print(-1)


(a, b, c, n) = [int(x) for x in input().split()]
pa = a - c
pb = b - c
if pa < 0 or pb < 0 or pa + pb + c > n - 1:
	print(-1)
else:
	print(n - (pa + pb + c))


a = input()
b = list(map(int, a.split()))
c = b[3] - (b[0] + b[1] - b[2])
if b[0] + b[1] - b[2] >= b[3] or b[2] > b[0] or b[2] > b[1]:
	print(-1)
else:
	print(c)


from __future__ import print_function
import sys
import math
import os.path
import random
from copy import deepcopy
from functools import reduce
from collections import Counter, ChainMap, defaultdict
from itertools import cycle, chain
from queue import Queue, PriorityQueue
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, nlargest, nsmallest
import bisect
from statistics import mean, mode, median, median_low, median_high

def log(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

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

def nio(offset):
	return map(lambda x: int(x) + offset, input().split())

def nia():
	return list(map(int, input().split()))

def toString(aList, sep=' '):
	return sep.join((str(x) for x in aList))

def toMapInvertIndex(aList):
	return {k: v for (v, k) in enumerate(aList)}

def sortId(arr):
	return sorted(range(arr), key=lambda k: arr[k])

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(a, b, c, n) = ni()
if a >= c and b >= c and (a + b - c < n):
	print(n - (a + b - c))
else:
	print(-1)


(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) = input().split()
(A, B, C, N) = (int(A), int(B), int(C), int(N))
temp_A = A - C
temp_B = B - C
temp = N - temp_A - temp_B - C
if temp_A < 0 or temp_B < 0 or A > N or (B > N) or (C > A) or (C > B):
	print(-1)
elif temp > 0:
	print(temp)
else:
	print(-1)


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


(a, b, c, n) = (int(x) for x in input().split())
if c > a or c > b:
	print(-1)
	quit()
ans = n - (a + b - c)
if ans < 1:
	print(-1)
else:
	print(ans)


b = []
for a in input().split():
	b.append(int(a))
c = b[3] - b[0] - b[1] + b[2]
if c <= 0 or b[0] > b[3] or b[1] > b[3] or (b[2] > b[3]) or (b[2] > b[0]) or (b[2] > b[1]):
	print('-1')
else:
	print(c)


(a, b, c, d) = map(int, input().split())
if d > a + b - c and c <= a and (c <= b):
	all_passed_students = a + b - c
	all_losed_students = d - all_passed_students
	print(all_losed_students)
else:
	print(-1)


s = input().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
n = int(s[3])
x = n - (a + b - c)
if a > n - 1 or b > n - 1 or c > min(a, b) or (x < 1):
	print('-1')
else:
	print(x)


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


(A, B, C, N) = [int(a) for a in input().split()]
bad = False
if A > N:
	bad = True
if B > N:
	bad = True
if C > N:
	bad = True
if A < C:
	bad = True
if B < C:
	bad = True
onlyA = A - C
onlyB = B - C
nothing = N - C - onlyA - onlyB
if nothing <= 0:
	bad = True
if bad:
	print(-1)
else:
	print(nothing)


(a, b, c, n) = map(int, input().split())
ok = True
a -= c
if a < 0:
	ok = False
b -= c
if b < 0:
	ok = False
if a + b + c >= n:
	ok = False
n -= a + b + c
if n <= 0:
	ok = False
print(n if ok else -1)


(a, b, c, n) = map(int, input().split())
aa = a - c
bb = b - c
ans = n - (aa + bb + c)
if ans > 0 and aa >= 0 and (bb >= 0) and (c >= 0):
	print(ans)
else:
	print('-1')


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
cat = ''.join
catn = '\n'.join
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]

def solve(a, b, c, n):
	if a < c or b < c:
		return -1
	m = n - (a + b - c)
	if m < 1:
		return -1
	return m
(a, b, c, n) = ris()
print(solve(a, b, c, n))


(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)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
from sys import stdin, stdout
input = stdin.readline

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

def LI():
	return list(map(int, sys.stdin.readline().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
abcn = LI()
if abcn[0] + abcn[1] - abcn[2] * 2 + abcn[2] >= abcn[3] or (abcn[0] < abcn[2] or abcn[1] < abcn[2]):
	print(-1)
else:
	print(abcn[3] - (abcn[0] + abcn[1] - abcn[2] * 2 + abcn[2]))


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(a, b, c, n) = LI()
	t = a + b - c
	if t >= n or a < c or b < c:
		return -1
	return n - t
print(main())


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


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


(a, b, c, n) = map(int, input().split())
n -= a + b - c
print((-1, n)[n > 0 and a >= c <= b])


def go():
	(a, b, c, n) = [int(i) for i in input().split(' ')]
	if a < c or b < c:
		return -1
	if a >= n or b >= n or c >= n:
		return -1
	A = a - c
	B = b - c
	C = c
	if A + B + C >= n:
		return -1
	return n - (A + B + C)
print(go())


(a, b, c, d) = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
temp = int(a - c)
temp1 = int(b - c)
ss = int(temp + temp1 + c)
if ss >= d:
	print('-1')
elif a < c:
	print('-1')
elif b < c:
	print('-1')
else:
	print(d - ss)


import sys
import math
import bisect

def solve(a, b, c, n):
	if a > n or b > n or a + b - c > n:
		return -1
	if c > a or c > b or c > n:
		return -1
	d = n - a - b + c
	if d == 0:
		return -1
	return d

def main():
	(a, b, c, n) = map(int, input().split())
	ans = solve(a, b, c, n)
	print(ans)
main()


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)


(a, b, c, d) = map(int, input().split())
if c > a or c > b:
	print(-1)
	exit(0)
a -= c
if a + b >= d:
	print(-1)
	exit(0)
print(d - a - b)


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))


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


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


(A, B, C, N) = map(int, input().split())
F = N - A - B + C
print(F if F > 0 and C <= min(A, B) else -1)


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


inputs = [int(x) for x in input().split()]
a = inputs[0]
b = inputs[1]
both = inputs[2]
n = inputs[3]
not_passed = n - (a + b - both)
if n < a or n < b or n < both:
	print(-1)
elif both > a or both > b:
	print(-1)
elif not_passed < 1:
	print(-1)
else:
	print(not_passed)


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


[A, B, C, N] = map(int, input().strip().split())
AvC = A - C
BvC = B - C
AB = A + BvC
R = N - AB
if min(AvC, BvC) < 0 or R < 1:
	print(-1)
else:
	print(R)


(a, b, c, d) = map(int, input().split())
A = a - c
B = b - c
C = c
N = d - (A + B + C)
if N >= 1 and A >= 0 and (B >= 0) and (C >= 0) and (d > a) and (d > b) and (d > c):
	print(N)
else:
	print(-1)


(a, b, c, n) = [int(x) for x in input().split()]
if a < n and b < n and (c <= min(a, b)) and (n > 0) and (n >= a + b - c + 1):
	print(n - (a + b - c))
else:
	print('-1')


(A, B, C, N) = list(map(int, input().split()))
a = A + B - C
t = N - a
print(t if A >= C and B >= C and (t > 0) else -1)


(A, B, C, N) = map(int, input().split())
Z = A + B - C
if A < C or B < C or Z >= N:
	print('-1')
else:
	print(N - Z)


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


num = [int(x) for x in input().split()]
if num[0] + num[1] - num[2] < num[3] and num[0] >= num[2] and (num[1] >= num[2]):
	print(num[3] - num[0] - num[1] + num[2])
else:
	print(-1)


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


(A, B, C, N) = list(map(int, input().strip().split()))
if C > A or C > B or A >= N or (B >= N):
	print(-1)
else:
	passed = A + B - C
	if passed >= N:
		print(-1)
	else:
		print(N - passed)


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ''.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
(a, b, c, n) = mi()
print(n - a - b + c) if n - a - b + c > 0 and a <= n and (b <= n) and (c <= a) and (c <= b) else print(-1)


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
P = lambda : map(int, input().split())
N = lambda : int(input())
(a, b, c, n) = P()
if a < c or b < c:
	r = -1
else:
	r = n - (a + b - c)
print(-1 if r <= 0 else r)


import sys
import math
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
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
(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)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


(a, b, c, n) = input().split(' ')
ap = int(a) - int(c)
bp = int(b) - int(c)
g = ap + bp + int(c)
tot = int(n) - g
if ap < 0 or bp < 0:
	print(-1)
elif tot < 1:
	print(-1)
else:
	print(tot)


(a, b, c, n) = map(int, input().split())
just_a = abs(c - a)
just_b = abs(c - b)
fail = n - just_a - just_b - c
if fail > 0 and c <= a and (c <= b):
	print(fail)
else:
	print(-1)


import sys

def main():
	A = list(map(int, sys.stdin.readline().split()))
	if A[0] < A[2] or A[1] < A[2] or A[1] + A[0] - A[2] >= A[3]:
		print(-1)
		return
	A[0] -= A[2]
	v = A[3] - sum(A[:2])
	if v <= 0:
		print(-1)
	else:
		print(A[3] - sum(A[:2]))
main()


(a, b, c, n) = [int(x) for x in input().split()]
res = n - (a + b - c)
if a > n or b > n or c > n or (c > a) or (c > b):
	print(-1)
elif res >= 1:
	print(res)
else:
	print(-1)


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


t = input()
L = t.split()
for i in range(4):
	L[i] = int(L[i])
x = L[3] - (L[0] + L[1] - L[2])
if x < 1 or L[3] < L[0] or L[3] < L[1] or (L[3] < L[2]) or (L[2] > L[0]) or (L[2] > L[1]):
	print(-1)
else:
	print(x)


from sys import *
input = stdin.readline
listInput = lambda : list(map(int, input().strip().split()))
lineInput = lambda : map(int, input().strip().split())
sJoin = lambda a, sep: f'{sep}'.join(a)
arrJoin = lambda a, sep: f'{sep}'.join(map(str, a))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(math.sqrt(n) + 1), 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def main():
	(a, b, c, n) = lineInput()
	check = a + b - c
	print(n - check if n - check > 0 and (a >= c and b >= c) else -1)
main()


(A, B, C, N) = map(int, input().split())
well_done = A + B - C
if well_done >= N or (A * B == 0 and C != 0) or A < C or (B < C):
	print(-1)
else:
	print(N - well_done)


(a, b, c, n) = input().split()
(a, b, c, n) = [int(a), int(b), int(c), int(n)]
diff1 = a - c
diff2 = b - c
s = diff1 + diff2 + c
if s >= n:
	print('-1')
elif c > a or c > b:
	print('-1')
else:
	print(n - s)


import sys, collections
(a, b, c, n) = map(int, sys.stdin.readline().split())
if n - (a - c + (b - c) + c) >= 1 and a - c >= 0 and (b - c >= 0):
	print(n - (a - c + (b - c) + c))
else:
	print(-1)


(q, w, e, r) = map(int, input().split())
a = r - q - (w - e)
if a < 1 or q < e or w < e:
	print(-1)
else:
	print(a)


def main():
	rd = lambda : list(map(int, input().split()))
	rd1 = lambda : int(input())
	(a, b, c, n) = rd()
	a -= c
	b -= c
	if a < 0 or b < 0:
		print(-1)
		return
	if n - a - b - c >= 1:
		print(n - a - b - c)
		return
	print(-1)
main()


(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) = map(int, input().split())

def isValid(a, b, c, n):
	if c > a or c > b:
		return -1
	failedStudent = n - (a - c + b - c + c)
	if failedStudent < 1:
		return -1
	return failedStudent
print(isValid(a, b, c, n))


(a, b, c, n) = map(int, input().split())
na = a - c
nb = b - c
if na < 0 or nb < 0:
	print(-1)
else:
	f = n - na - nb - c
	if f < 1:
		print(-1)
	else:
		print(f)


(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)


arr = input().split(' ')
A = int(arr[0])
B = int(arr[1])
C = int(arr[2])
N = int(arr[3])
fail = N - (A + B - C)
if C > B or C > A:
	print(-1)
elif fail <= 0:
	print(-1)
else:
	print(fail)


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


(A, B, C, N) = map(int, input().split(' '))
A1 = A - C
B1 = B - C
j = 0
if A1 < 0:
	j = 1
if B1 < 0:
	j = 1
W = A1 + B1 + C
if W == N or W > N:
	j = 1
if A == 0 and C != 0:
	j = 1
if B == 0 and C != 0:
	j = 1
if j == 1:
	print('-1')
else:
	W = N - W
	print(W)


(a, b, c, n) = map(int, input().split())
aa = a - c
bb = b - c
if aa < 0 or bb < 0:
	print(-1)
	exit(0)
feast = aa + bb + c
stay = n - feast
if stay < 1:
	print(-1)
	exit(0)
print(stay)


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


input_arr = [int(x) for x in input().split(' ')]
a = int(input_arr[0])
b = int(input_arr[1])
c = int(input_arr[2])
n = int(input_arr[3])
fail = n - (a + b - c)
if fail < 1:
	print(str(-1))
elif n < a or n < b or n < c:
	print(str(-1))
elif c > a or c > b:
	print(str(-1))
elif n < 1:
	print(str(-1))
else:
	print(str(fail))


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


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


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


(bug, beaver, both, students) = map(int, input().split())
if bug - both + (beaver - both) + both < students and students > 0 and (bug >= both) and (beaver >= both) and (both < students):
	print(str(students - (bug - both + (beaver - both) + both)))
else:
	print(-1)


def main():
	(A, B, C, N) = list(map(int, input().split()))
	if C > A or C > B or C > N or (A > N) or (B > N):
		print(-1)
	elif N - A - B + C >= 1:
		print(N - A - B + C)
	else:
		print(-1)
	return 0
main()


(mecces, burgerKing, both, groupSize) = map(int, input().strip().split(' '))
mecces -= both
burgerKing -= both
notPassed = groupSize - sum((mecces, burgerKing, both))
if notPassed > 0 and burgerKing >= 0 and (mecces >= 0):
	print(notPassed)
else:
	print(-1)


(d, k, b, h) = map(int, input().split())
f = h - (d - b + (k - b) + b)
if f < 1 or d < b or k < b:
	f = -1
print(f)


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


X = list(map(int, input().split()))
Pass = X[0] + X[1] - X[2]
print(-1 if Pass >= X[3] or X[2] > X[0] or X[2] > X[1] else X[3] - Pass)


import sys
a = sys.stdin.read()
a = a.split()
student_pass = int(a[0]) + int(a[1]) - int(a[2])
if int(a[0]) < int(a[2]) or int(a[1]) < int(a[2]):
	print(-1)
elif student_pass < 0:
	print(-1)
elif student_pass >= int(a[3]):
	print(-1)
else:
	print(int(a[3]) - student_pass)


(a, b, c, n) = map(int, input().split())
if a >= n or b >= n or a < c or (b < c) or (a < 0) or (b < 0):
	print('-1')
	exit(0)
tot = a + b - c
if tot >= n:
	print('-1')
	exit(0)
print(n - tot)


def peresdacha(a, b, c, n):
	if a - c >= 0 and b - c >= 0 and (c >= 0) and (n - a - b + c > 0):
		return n - a - b + c
	return -1
(A, B, C, N) = [int(i) for i in input().split()]
print(peresdacha(A, B, C, N))


def go():
	(A, B, C, N) = [int(i) for i in input().split(' ')]
	A -= C
	B -= C
	if A + B + C >= N or A < 0 or B < 0:
		return -1
	else:
		return N - (A + B + C)
	return
print(go())


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


(A, B, C, N) = map(int, input().split())
ans = N - (A + B - C)
if ans <= 0 or ans > N or N < max(A, B, C) or (C > min(A, B)):
	print(-1)
	exit()
print(ans)


(A, B, C, N) = map(int, input().split())
if C > A or C > B:
	print(-1)
	exit()
else:
	A -= C
	B -= C
pass_students = A + B + C
if pass_students < N:
	print(N - pass_students)
	exit()
else:
	print(-1)


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


(num1, num2, num3, num4) = map(int, input().split())
num4 -= num1 + num2 - num3
if num4 <= 0 or num3 > num2 or num1 < num3:
	print(-1)
else:
	print(num4)


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


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)
	exit()
total = only_b + only_a + c
if total >= n:
	print(-1)
	exit()
print(n - only_a - only_b - c)


from sys import stdin, stdout
lst = list(map(int, input().strip().split()))
total_pass = lst[0] + lst[1] - lst[2]
total = lst[3]
if lst == [0, 0, 0, 0]:
	stdout.write('-1')
elif total_pass >= total or lst[0] >= lst[3] or lst[1] >= lst[3] or (lst[2] >= lst[3]) or (total_pass < 0) or (lst[0] < lst[2]) or (lst[1] < lst[2]):
	stdout.write(str(-1))
else:
	fail = total - total_pass
	stdout.write(str(fail))


import math
import fractions
s = list(map(int, input().split()))
(a, b, c, n) = (s[0], s[1], s[2], s[3])
res = n - (a + b - c)
if c <= a and c <= b and (a <= n) and (b <= n) and (res > 0):
	print(res)
else:
	print(-1)


inputs = list(map(int, input().split(' ')))
a = inputs[0]
b = inputs[1]
c = inputs[2]
n = inputs[3]
remaining = n - a - b + c
if c > a or c > b:
	print('-1')
elif remaining >= 1:
	print(remaining)
else:
	print('-1')


(a, b, c, n) = [int(x) for x in input().split()]
a -= c
b -= c
if a < 0 or b < 0:
	print(-1)
	exit()
ans = n - (a + b + c)
if ans > 0:
	print(ans)
else:
	print(-1)


some_chars = input()
sharps = some_chars.split()
BD = int(sharps[0])
BK = int(sharps[1])
all_cafe = int(sharps[2])
students = int(sharps[3])
ans = students - BD - BK + all_cafe
if ans <= 0 or students < all_cafe or students < BK or (students < BD) or (BD == 0 and all_cafe > 0) or (BK == 0 and all_cafe > 0) or (students == 0) or (all_cafe > BK) or (all_cafe > BD):
	print(-1)
else:
	print(ans)


def solve(a, b, c, n):
	if n < 1:
		return -1
	if c > a or c > b:
		return -1
	cnt = a + b - c
	if cnt > n - 1:
		return -1
	return n - cnt
(a, b, c, n) = map(int, input().split())
print(solve(a, b, c, n))


from sys import argv
import sys
(a, b, c, n) = [int(x) for x in input().split()]
succeeded = a + b - c
failed = n - succeeded
if failed < 1:
	print('-1')
elif a < c or b < c:
	print('-1')
else:
	print(failed)


(A, B, C, N) = map(int, input().split())
A -= C
B -= C
if A < 0 or B < 0:
	print(-1)
else:
	sm = A + B + C
	if sm > N - 1:
		print(-1)
	else:
		print(N - sm)


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


(a, b, c, n) = [int(i) for i in input().split()]
x = a - c
y = b - c
z = n - (x + y + c)
if z > 0 and x >= 0 and (y >= 0):
	print(z)
else:
	print(-1)


(a, b, c, n) = map(int, input().split())
pp = a + b - c
ff = n - pp
print(ff if ff > 0 and c <= a and (c <= b) else -1)


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


(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)


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


raw = input().split(' ')
A = int(raw[0])
B = int(raw[1])
C = int(raw[2])
N = int(raw[3])
if A + B - C > N - 1:
	print(-1)
	exit()
if A < C or B < C:
	print(-1)
	exit()
justA = A - C
justB = B - C
stayedHome = N - justA - justB - C
if stayedHome > 0 and stayedHome < 101:
	print(stayedHome)
else:
	print(-1)


(a, b, c, n) = [int(x) for x in input().split()]
t = True
a1 = a - c
b1 = b - c
if a1 < 0 or b1 < 0:
	t = False
e = n - a1 - b1 - c
if e <= 0:
	t = False
if t == False:
	print(-1)
	exit()
else:
	print(e)


import sys
import math
(A, B, C, N) = map(int, input().split())
if C > A or C > B:
	print(-1)
elif A - C + (B - C) + C >= N:
	print(-1)
elif N == 0 and N == 1:
	print(-1)
else:
	print(N - (A - C) - (B - C) - C)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

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


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


(A, B, C, N) = list(map(int, input().split()))
Af = A - C
Bf = B - C
Nf = N - C
result = Nf - (Af + Bf)
if Af < 0 or Bf < 0 or Nf < 0 or (result < 1):
	print(-1)
else:
	print(result)


def main():
	(a, b, c, n) = map(int, input().split())
	r = a - c + (b - c) + c
	if c <= a and c <= b and (r + 1 <= n):
		print(n - r)
	else:
		print(-1)
main()


(ta, tb, tc, td) = input().split()
a = int(ta)
b = int(tb)
c = int(tc)
d = int(td)
if a + b - c >= d or c > a or c > b:
	print(-1)
else:
	print(d - (a + b - c))


def main():
	(a, b, c, n) = map(int, input().split())
	num = n - (a + b - c)
	if num <= 0 or a > n or b > n or (c > n) or (a < c) or (b < c):
		return -1
	return num
print(main())


a = input().split()
b = []
for i in range(len(a)):
	b.append(int(a[i]))
res = b[3] - (b[0] + b[1] - b[2])
d = -1
if res >= 1 and b[0] >= b[2] and (b[1] >= b[2]):
	print(res)
else:
	print(d)


R = lambda : map(int, input().split())
(a, b, c, n) = R()
ans = n - a - b + c
if ans <= 0 or c > a or c > b or (a > n) or (b > n):
	ans = -1
print(ans)


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


(a, b, c, n) = map(int, input().strip().split())
f = n + c - a - b
x = max(a, b, c, n - 1)
if x != n - 1 or f < 1 or a < c or (b < c):
	print(-1)
else:
	print(f)


def test_1():
	import math
	from collections import Counter
	(a, b, c, n) = list(map(int, input().split(' ')))
	if a < c or b < c:
		print(-1)
		return
	a_1 = n - (a - c) - (b - c) - c
	if a_1 < 1:
		print(-1)
		return
	else:
		print(a_1)
test_1()


def failed_exams():
	places = list(map(int, input().split()))
	if places[0] > places[3] or places[1] > places[3] or places[2] > places[3]:
		return -1
	temp = places[2]
	places[0] -= temp
	places[1] -= temp
	places[3] -= temp
	if places[0] < 0 or places[1] < 0:
		return -1
	places[3] -= places[0]
	places[3] -= places[1]
	if places[3] < 0:
		return -1
	else:
		if places[3] == 0:
			return -1
		return places[3]
A = failed_exams()
print(A)


import argparse

def main():
	(a, b, c, N) = [int(i) for i in input().split()]
	answer = N - a - b + c
	if answer < 1 or N < a or N < b or (a < c) or (b < c):
		print(-1)
	else:
		print(answer)
main()


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()


r = input().split()
for i in range(len(r)):
	r[i] = int(r[i])
a = int(r[0])
b = int(r[1])
c = int(r[2])
n = int(r[3])
if int(a - c) < 0 or int(b - c) < 0 or c < 0 or (int(n - (a + b - c)) <= 0):
	print(int(-1))
else:
	print(int(n - (a + b - c)))


(a, b, c, n) = map(int, input().split())
for i in range(1, n + 1):
	tmp = n - i
	if a >= c and b >= c and (a + b - c == tmp):
		print(i)
		break
else:
	print(-1)


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


def solve(a, b, c, n):
	if a < c or b < c:
		return -1
	a -= c
	b -= c
	if a + b + c >= n:
		return -1
	return n - (a + b + c)

def main():
	arr = list(map(int, input().split(' ')))
	print(solve(*arr))
main()


(a, b, c, n) = [int(x) for x in input().split()]
(ra, rb, u, k) = (a - c, b - c, a + b - c, n - (a + b - c))
print(k if k >= 1 and ra >= 0 and (rb >= 0) and (u >= 0) else -1)


def f(a, b, c, n):
	if a < c:
		return -1
	if b < c:
		return -1
	x = a + b - c
	if x + 1 <= n:
		return n - x
	else:
		return -1
(a, b, c, n) = [int(i) for i in input().split()]
print(f(a, b, c, n))


import sys

def read_line():
	return [int(n) for n in sys.stdin.readline().split()]

def celebrated(mcdon, burg, both):
	only_mcdon = mcdon - both
	only_burg = burg - both
	if only_mcdon < 0 or only_burg < 0:
		return float('inf')
	return sum([only_mcdon, only_burg, both])
(A, B, C, N) = read_line()
passed_exam = celebrated(A, B, C)
if passed_exam + 1 > N:
	print(-1)
else:
	print(N - passed_exam)


def a():
	(a, b, c, n) = map(int, input().split())
	p = n - (a + b - c)
	if p <= 0 or a < c or b < c:
		return -1
	else:
		return p
print(a())


(a, b, c, d) = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
if d > a + b - c and (a >= c and b >= c):
	print(d - a - b + c)
else:
	print(-1)


(a, b, both, n) = (int(x) for x in input().split())
passed = a + b - both
failed = n - passed
print(failed if failed > 0 and a >= both and (b >= both) else -1)


(A, B, C, N) = map(int, input().split())
D = A - C
E = B - C
if D < 0 or E < 0:
	print(-1)
elif D + E + C < N:
	print(N - D - E - C)
else:
	print(-1)


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


students = list(map(int, input().split()))
remnder_students = 0
if students[-1] < students[0] or students[-1] < students[1] or students[-1] < students[2]:
	print(-1)
elif students[2] > students[0] or students[2] > students[1]:
	print(-1)
else:
	remnder_students = students[-1] - (students[0] - students[2] + (students[1] - students[2]) + students[2])
	if remnder_students < 1:
		print(-1)
	else:
		print(remnder_students)


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


def ii():
	return int(input())

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

def li():
	return list(mi())
(A, B, C, N) = mi()
U = A + B - C
if N == 0 or U >= N or C > min(A, B) or (max(A, B) > N):
	print(-1)
else:
	print(N - U)


from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from collections import defaultdict
import math
cin = stdin.readline

def cout(x):
	stdout.write(str(x) + '\n')

def nexint():
	return int(stdin.readline())

def readline():
	return map(int, stdin.readline().split())

def readlist():
	return list(map(int, stdin.readline().split()))

def sorted_indexes(arr):
	return sorted(range(len(arr)), key=arr.__getitem__)

def printr(arr):
	[stdout.write(str(x) + ' ') for x in arr]
	cout('')

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return a[i]
	raise ValueError
(a, b, c, n) = readline()
p = a + b - c
if a >= c and b >= c and (p >= 0) and (n >= 0) and (n - p >= 1):
	cout(n - p)
else:
	cout(-1)


n = [int(num) for num in input().split()]
c = n[3] + n[2] - n[1] - n[0]
if c > 0 and n[2] <= n[1] and (n[2] <= n[0]):
	print(c)
else:
	print(-1)


import sys
import math
import collections
from pprint import pprint as pp
mod = 998244353
MAX = 10 ** 10

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

def array():
	return list(map(int, input().split()))

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat
(a, b, c, n) = inp()
temp = a + b - c
if c > a or c > b or temp < 0:
	print(-1)
	sys.exit()
if n - temp <= 0:
	print(-1)
else:
	print(n - temp)


(A, B, C, N) = map(int, input().split())
x = A - C
y = B - C
S = N - x - y - C
if C <= A and C <= B:
	if S > 0:
		print(S)
	else:
		print(-1)
else:
	print(-1)


def rli():
	return list(map(int, input().split()))

def main():
	(a, b, c, n) = rli()
	if c > a or c > b:
		print(-1)
		return
	if a + b - c > n - 1:
		print(-1)
		return
	print(n - a - b + c)
main()


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


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


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


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
sys.setrecursionlimit(10000)

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(A, B, C, N):
	if N - 1 < A:
		return -1
	if N - 1 < B:
		return -1
	if A < C:
		return -1
	if B < C:
		return -1
	ans = N - (A + B - C)
	if ans < 1:
		return -1
	return ans

def main():
	(A, B, C, N) = read_int_n()
	print(slv(A, B, C, N))
main()


(A, B, C, N) = map(int, input().strip().split())
flag = True
if C > A or C > B:
	flag = False
D = N - (A - C) - B
if D >= 1 and flag:
	print(D)
else:
	print(-1)


def check(n, index, lista):
	for i in range(n):
		if lista[i] > lista[index]:
			return True
	return False

def check2(n, index, lista):
	for i in range(n):
		if lista[i] < lista[index]:
			return True
	return False
x = [int(x) for x in input().split()]
contradics = False
if check(3, -1, x) or check2(2, 2, x):
	contradics = True
if x[2]:
	for i in range(2):
		x[i] -= x[2]
suma = sum(x[:-1])
ans = x[-1] - suma
if contradics or ans <= 0:
	print(-1)
else:
	print(ans)


(a, b, c, n) = [int(i) for i in input().strip().split(' ')]
if a < 0 or b < 0 or c < 0 or (n < 0):
	print(-1)
	exit()
if n == 0:
	print(-1)
	exit()
if c > a or c > b:
	print(-1)
	exit()
went = a + b - c
if went >= n:
	print(-1)
	exit()
failed = n - went
print(failed)


data = [int(n) for n in input('').split()]
A = data[0]
B = data[1]
C = data[2]
N = data[3]
if A + B - C < N and A >= C and (B >= C) and (A < N) and (B < N) and (C < N):
	print(N - (A + B - C))
else:
	print(-1)


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


arr = input().split()
arr = [int(x) for x in arr]

def solution():
	global arr
	arr[0] -= arr[2]
	arr[1] -= arr[2]
	if arr[0] < 0 or arr[1] < 0:
		print(-1)
		return
	arr[3] -= arr[0] + arr[1] + arr[2]
	if arr[3] < 1:
		print(-1)
		return
	else:
		print(arr[3])
		return
solution()


(A, B, C, N) = [int(x) for x in input().split()]
d = A - C
e = B - C
if N - (d + e + C) > 0 and A >= C and (B >= C):
	print(N - (d + e + C))
else:
	print(-1)


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


(a, b, c, n) = map(int, input().split())
x = a - c
y = b - c
sum = n - x - y - c
if x >= 0 and y >= 0 and (c >= 0) and (sum > 0):
	print(sum)
else:
	print(-1)


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


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