Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!

Sonya is an owl and she sleeps during the day and stay awake from minute l_1 to minute r_1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.

Filya works a lot and he plans to visit Sonya from minute l_2 to minute r_2 inclusive.

Calculate the number of minutes they will be able to spend together.


-----Input-----

The only line of the input contains integers l_1, r_1, l_2, r_2 and k (1 ≤ l_1, r_1, l_2, r_2, k ≤ 10^18, l_1 ≤ r_1, l_2 ≤ r_2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.


-----Output-----

Print one integer — the number of minutes Sonya and Filya will be able to spend together.


-----Examples-----
Input
1 10 9 20 1

Output
2

Input
1 100 50 200 75

Output
50



-----Note-----

In the first sample, they will be together during minutes 9 and 10.

In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.

Difficulty: EASY

Solutions:
(l1, r1, l2, r2, k) = [int(x) for x in input().split()]
left = max(l1, l2)
right = min(r1, r2)
if left > right:
	print('0')
elif k <= right and k >= left:
	print(right - left)
else:
	print(right - left + 1)


(l, r, ll, rr, k) = map(int, input().split())
l = max(l, ll)
r = min(r, rr)
ans = r - l + 1
if k in range(l, r + 1):
	ans -= 1
print(ans if ans > 0 else 0)


(l1, r1, l2, r2, k) = map(int, input().split())
l = max(l1, l2)
r = min(r1, r2)
if l > r:
	print(0)
elif l <= k <= r:
	print(r - l)
else:
	print(r - l + 1)


(a, b, x, y, k) = map(int, input().split())
(r, l) = (max(a, x), min(b, y))
if k >= r and l >= k:
	print(max(0, l - r))
else:
	print(max(0, l - r + 1))


__author__ = 'Alexander'
import sys
(l1, r1, l2, r2, k) = map(int, sys.stdin.readline().split())
a = max(l1, l2)
b = min(r1, r2)
length = max(0, b - a + 1)
if length != 0 and k >= a and (k <= b):
	length -= 1
sys.stdout.write(str(length))


(a, b, n, m, k) = map(int, input().split())
l = max(a, n)
r = min(b, m)
t = r - l + 1
if l <= k <= r:
	t -= 1
print(max(t, 0))


(l1, r1, l2, r2, k) = map(int, input().split())
if l1 > r2 or r1 < l2:
	print(0)
	quit()
t = max(min(r1, r2) - max(l1, l2), 0) + 1
if (k >= l2 and k <= r2) and (k >= l1 and k <= r1):
	t -= 1
print(t)


(l1, r1, l2, r2, k) = map(int, input().split())
l = max(l1, l2)
r = min(r1, r2)
s = r - l + 1
if l <= k and k <= r:
	s -= 1
print(max(0, s))


temp = input().split()
l1 = int(temp[0])
r1 = int(temp[1])
l2 = int(temp[2])
r2 = int(temp[3])
k = int(temp[4])
t = 0
l = max(l1, l2)
r = min(r1, r2)
if r >= l:
	t += r - l + 1
if l <= k and k <= r:
	t -= 1
print(t)


(a, b, c, d, k) = map(int, input().split())
a = max(a, c)
b = min(b, d)
print(max(0, b - a + 1 - (a <= k <= b)))


(l1, r1, l2, r2, k) = map(int, input().split())
l = max(l1, l2)
r = min(r1, r2)
print(max(0, r - l + 1) - (l <= k <= r))


def gosti(l_1, r_1, l_2, r_2, k):
	if r_1 < l_2 or l_1 > r_2:
		return 0
	m = max(l_1, l_2)
	n = min(r_1, r_2)
	if max(l_1, l_2) <= k <= min(r_1, r_2):
		return min(r_1, r_2) - max(l_1, l_2)
	return min(r_1, r_2) - max(l_1, l_2) + 1
(a1, b1, a2, b2, K) = [int(i) for i in input().split()]
print(gosti(a1, b1, a2, b2, K))


inp = list(map(int, input().split()))
l = max(inp[0], inp[2])
r = min(inp[1], inp[3])
k = inp[4]
if l <= r:
	time = r - l + 1
	if k >= l and k <= r:
		time = time - 1
	if time <= 0:
		time = 0
else:
	time = 0
print(time)


(l1, r1, l2, r2, k) = map(int, input().split())
r1 += 1
r2 += 1
(left, right) = (max(l1, l2), min(r1, r2))
ans = right - left
if left <= k < right:
	ans -= 1
print(max(ans, 0))


input_num = list(map(int, input().split()))
(l1, r1, l2, r2, k) = input_num
t = min(r1, r2) - max(l1, l2) + 1
if t < 0:
	t = 0
elif max(l1, l2) <= k <= min(r1, r2):
	t -= 1
print(t)


(l1, r1, l2, r2, k) = map(int, input().split())
s = max(l1, l2)
e = min(r1, r2)
re = e - s
if re < 0:
	print(0)
elif k <= e and k >= s:
	print(re)
else:
	print(re + 1)


lst = list(map(int, input().split()))
a = lst[0:2]
b = lst[2:4]
c = lst[4]
srt = []
srt.append(a)
srt.append(b)
srt.sort(key=lambda list: list[0])
a = srt[0]
b = srt[1]
interval = a[1] - b[0] + 1
if interval > 0:
	if a[1] >= b[1]:
		interval = b[1] - b[0] + 1
	if c >= b[0] and c <= min(a[1], b[1]):
		interval -= 1
	print(interval)
else:
	print(0)


(l1, r1, l2, r2, k) = map(int, input().split())
if l1 > l2:
	(l1, l2) = (l2, l1)
	(r1, r2) = (r2, r1)
if r1 < l2:
	print(0)
elif r1 < r2:
	if k < l2 or k > r1:
		print(r1 - l2 + 1)
	else:
		print(r1 - l2)
elif k < l2 or k > r2:
	print(r2 - l2 + 1)
else:
	print(r2 - l2)


(l1, r1, l2, r2, k) = [int(i) for i in input().split()]
l = max(l1, l2)
r = min(r1, r2)
if l > r:
	print(0)
elif l <= k <= r:
	print(r - l)
else:
	print(r - l + 1)


s = [int(S) for S in input().split()]
(l1, r1, l2, r2, k) = (s[0], s[1], s[2], s[3], s[4])
if l1 <= l2 <= r1 <= r2:
	if l2 <= k <= r1:
		print(r1 - l2)
	else:
		print(r1 - l2 + 1)
elif l1 <= r1 <= l2 <= r2:
	if r1 == l2 == k or r1 != l2:
		print(0)
	else:
		print(1)
elif l2 <= l1 <= r1 <= r2:
	if l1 <= k <= r1:
		print(r1 - l1)
	else:
		print(r1 - l1 + 1)
elif l2 <= l1 <= r2 <= r1:
	if l1 <= k <= r2:
		print(r2 - l1)
	else:
		print(r2 - l1 + 1)
elif l1 <= l2 <= r2 <= r1:
	if l2 <= k <= r2:
		print(r2 - l2)
	else:
		print(r2 - l2 + 1)
elif r2 == l1 and r2 != k:
	print(1)
else:
	print(0)


import sys
inf = float('inf')
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

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

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

def input():
	return sys.stdin.readline().strip()
(l1, r1, l2, r2, k) = get_ints()
mini1 = max(l1, l2)
mini2 = min(r1, r2)
ans = mini2 - mini1 + 1
if mini1 <= k <= mini2:
	ans -= 1
print(max(ans, 0))


(l_1, r_1, l_2, r_2, k) = list(map(int, input().split()))
ans = min(r_1, r_2) - max(l_1, l_2) + 1
if max(l_1, l_2) <= k <= min(r_1, r_2):
	ans -= 1
if ans < 0:
	ans = 0
print(ans)


s = input()
A = s.split(' ')
l1 = int(A[0])
r1 = int(A[1])
l2 = int(A[2])
r2 = int(A[3])
k = int(A[4])
l = max(l1, l2)
r = min(r1, r2)
if l > r:
	print(0)
elif k >= l and k <= r:
	print(r - l)
else:
	print(r - l + 1)


import sys

def main():
	(l1, r1, l2, r2, k) = [int(i) for i in sys.stdin.readline().strip().split()]
	l = max(l1, l2)
	r = min(r1, r2)
	if l <= r:
		print(r - l + 1 - (1 if l <= k <= r else 0))
	else:
		print(0)
main()


data = [int(info) for info in input().split(' ')]
if data[0] == data[2] and data[1] == data[3]:
	time = data[1] - data[0] + 1
	if data[4] >= data[0] and data[4] <= data[1]:
		time -= 1
elif (data[2] < data[0] and data[2] < data[1]) and (data[3] < data[0] and data[3] < data[1]) or ((data[1] < data[2] and data[0] < data[2]) and (data[0] < data[3] and data[0] < data[3])):
	time = 0
elif data[0] < data[2]:
	if data[1] < data[3]:
		time = data[1] - data[2] + 1
		if data[4] <= data[1] and data[4] >= data[2]:
			time -= 1
	else:
		time = data[3] - data[2] + 1
		if data[4] <= data[3] and data[4] >= data[2]:
			time -= 1
elif data[1] > data[3]:
	time = data[3] - data[0] + 1
	if data[4] <= data[3] and data[4] >= data[0]:
		time -= 1
else:
	time = data[1] - data[0] + 1
	if data[4] >= data[0] and data[4] <= data[1]:
		time -= 1
print(time)


(l1, r1, l2, r2, k) = map(int, input().split())
answ = r2 - l2 + 1
if r1 < r2:
	answ -= r2 - r1
if l2 < l1:
	answ -= l1 - l2
if k <= r1 and k <= r2 and (k >= l1) and (k >= l2):
	answ -= 1
if answ < 0:
	answ = 0
print(answ)


(l1, r1, l2, r2, k) = map(int, input().split())
st = max(l1, l2)
en = min(r1, r2)
cmin = en - st + 1
if st <= k and k <= en:
	cmin -= 1
print(max(0, cmin))


(l1, r1, l2, r2, k) = map(int, input().split())
borders = [max(l1, l2), min(r1, r2)]
if borders[1] < borders[0]:
	print(0)
else:
	res = borders[1] - borders[0]
	if k >= borders[0] and k <= borders[1]:
		print(res)
	else:
		print(res + 1)


(la, ra, lb, rb, k) = map(int, input().split())
s = max(la, lb)
e = min(ra, rb)
if s > e:
	print(0)
else:
	ans = 0
	if k >= s and k <= e and (k >= la) and (k <= ra):
		ans = e - s
	else:
		ans = e - s + 1
	print(ans)


import sys
(l1, r1, l2, r2, k) = map(int, sys.stdin.readline().split())
a = max(l1, l2)
b = min(r1, r2)
ans = 0
if a <= b:
	ans = b - a + 1
	if a <= k and k <= b:
		ans -= 1
print(ans)


(l1, r1, l2, r2, k) = map(int, input().split())
ans = 0
L = max(l2, l1)
R = min(r2, r1)
if L <= R:
	ans = R - (L - 1)
	if L <= k and R >= k:
		ans = ans - 1
print(ans)


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


(l1, r1, l2, r2, k) = map(int, input().split())
(l3, r3) = (max(l1, l2), min(r1, r2))
print(max(0, r3 - l3 + 1 - (k in range(l3, r3 + 1))))


string = input()
numbers = string.split()
for x in range(5):
	numbers[x] = int(numbers[x])
a = numbers[0]
b = numbers[1]
c = numbers[2]
d = numbers[3]
e = numbers[4]
p = max([a, c])
q = min([b, d])
r = q - p + 1
if p <= e <= q:
	r -= 1
if r < 0:
	r = 0
print(r)


s = input().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
k = int(s[4])
if b < c or d < a:
	print(0)
else:
	L = []
	L.append(a)
	L.append(b)
	L.append(c)
	L.append(d)
	L.sort()
	x = abs(L[2] - L[1]) + 1
	if k <= L[2] and k >= L[1]:
		x -= 1
	print(x)


(a, b, c, d, e) = map(int, input().split())
f = max(a, c)
g = min(b, d)
if f > g:
	print(0)
else:
	print(g - f + int(not f <= e <= g))


(l1, r1, l2, r2, k) = map(int, input().split())
(begin, end) = (max(l1, l2), min(r1, r2))
print(max(end - begin + (begin > k or k > end), 0))


(l11, l12, l21, l22, prink) = [int(x) for x in input().split()]
begin = max(l11, l21)
ends = min(l12, l22)
meeting = max(0, ends - begin + 1)
meeting -= begin <= prink <= ends
print(meeting)


(l1, r1, l2, r2, k) = [int(num) for num in input().split()]
range = [max([l1, l2]), min(r1, r2)]
numMinutes = range[1] - range[0] + 1
if k >= range[0] and k <= range[1]:
	numMinutes -= 1
if numMinutes > 0:
	print(numMinutes)
else:
	print(0)


(l1, r1, l2, r2, k1) = map(int, input().split())
k = 0
if l1 <= l2 and r2 <= r1:
	k = abs(r2 - l2) + 1
	if k1 >= l2 and k1 <= r2:
		k = k - 1
if l2 <= l1 and r2 >= r1:
	k = abs(r1 - l1) + 1
	if k1 >= l1 and k1 <= r1:
		k = k - 1
if l2 <= l1 and r1 >= r2 and (r2 >= l1):
	k = abs(l1 - r2) + 1
	if k1 >= l1 and k1 <= r2:
		k = k - 1
if l1 <= l2 and r1 <= r2 and (r1 >= l2):
	k = abs(l2 - r1) + 1
	if k1 >= l2 and k1 <= r1:
		k = k - 1
print(k)


(l, r, a, b, k) = map(int, input().split())
if a > l:
	l = a
if b < r:
	r = b
print(max(r - l + 1 - (l <= k <= r), 0))


(l, r, m, n, k) = [int(n) for n in input().split()]
if m > r:
	print(0)
elif n < l:
	print(0)
else:
	start = max(l, m)
	finish = min(r, n)
	if k >= start and k <= finish:
		print(finish - start)
	else:
		print(finish - start + 1)


(i1, s1, i2, s2, k) = map(int, input().split())
if i2 <= s1 and i2 >= i1 and (s2 >= s1):
	if k >= i2 and k <= s1:
		print(s1 - i2)
	else:
		print(s1 - i2 + 1)
elif i2 >= i1 and i2 <= s1 and (s2 <= s1):
	if k >= i2 and k <= s2:
		print(s2 - i2)
	else:
		print(s2 - i2 + 1)
elif i1 <= s2 and i1 >= i2 and (s1 >= s2):
	if k >= i1 and k <= s2:
		print(s2 - i1)
	else:
		print(s2 - i1 + 1)
elif i1 <= s2 and i1 >= i2 and (s1 <= s2):
	if k >= i1 and k <= s1:
		print(s1 - i1)
	else:
		print(s1 - i1 + 1)
else:
	print(0)


import math
(l1, r1, l2, r2, k) = map(int, input().split())
nach = max(l1, l2)
kon = min(r1, r2)
if nach > kon:
	print(0)
elif nach <= k <= kon:
	print(kon - nach)
else:
	print(kon - nach + 1)


import sys
arr = list(map(int, input().split()))
l1 = arr[0]
r1 = arr[1]
l2 = arr[2]
r2 = arr[3]
k = arr[4]
cnt = 0
a = max(l1, l2)
b = min(r1, r2)
if a > b:
	print(0)
elif a <= k and k <= b:
	print(b - a)
else:
	print(b - a + 1)


(l1, r1, l2, r2, k) = map(int, input().split())
p = max(l1, l2)
q = min(r1, r2)
m = q - p + 1
if k >= p and k <= q:
	m -= 1
print(m if q >= p else '0')


(a, b, c, d, k) = map(int, input().split())
x = max(a, c)
y = min(b, d)
if a > d or c > b:
	print('0\n')
elif k >= x and k <= y:
	print(y - x)
else:
	print(y - x + 1)


(a, b, c, d, k) = map(int, input().split())
if c >= a and d >= b and (c <= b):
	ans = b - c + 1
	if c <= k <= b:
		print(ans - 1)
		exit()
	print(ans)
	exit()
elif a <= c and d <= b:
	ans = d - c + 1
	if c <= k <= d:
		print(ans - 1)
		exit()
	print(ans)
	exit()
elif c <= a and b <= d:
	ans = b - a + 1
	if a <= k <= b:
		print(ans - 1)
		exit()
	print(ans)
	exit()
elif c <= a and d <= b and (a <= d):
	ans = d - a + 1
	if a <= k <= d:
		print(ans - 1)
		exit()
	print(ans)
	exit()
elif a == c and b == d:
	ans = a - b + 1
	if a <= k <= b:
		print(ans - 1)
		exit()
	print(ans)
	exit()
elif b == c:
	print(1 if k != b else 0)
	exit()
elif a == d:
	print(1 if k != a else 0)
	exit()
else:
	print(0)


arg = [int(i) for i in input().split()]
if arg[1] < arg[2] or arg[3] < arg[0]:
	print(0)
elif arg[0] <= arg[2] and arg[1] <= arg[3]:
	print(arg[1] - arg[2] - (arg[4] <= arg[1] and arg[4] >= arg[2]) + 1)
elif arg[0] <= arg[2] and arg[1] >= arg[3]:
	print(arg[3] - arg[2] - (arg[4] <= arg[3] and arg[4] >= arg[2]) + 1)
elif arg[0] >= arg[2] and arg[1] <= arg[3]:
	print(arg[1] - arg[0] - (arg[4] <= arg[1] and arg[4] >= arg[0]) + 1)
else:
	print(arg[3] - arg[0] - (arg[4] <= arg[3] and arg[4] >= arg[0]) + 1)


(L1, R1, L2, R2, K) = map(int, input().split())
ans = 0
L = max(L1, L2)
R = min(R1, R2)
if L <= R:
	ans = R - L + 1
	if L <= K <= R:
		ans -= 1
print(ans)


a = input().split()
l = a[0]
r = a[1]
l1 = a[2]
r1 = a[3]
k = a[4]
ansl = int(max(int(l), int(l1)))
ansr = int(min(int(r1), int(r)))
ans = 0
if int(k) >= int(ansl) and int(k) <= int(ansr):
	ans = -1
result = ans + ansr - ansl + 1
if int(r) < int(l1):
	print(0)
elif int(result) < 0:
	print(0)
else:
	print(int(ans) + int(ansr) - int(ansl) + int(1))


(l1, r1, l2, r2, k) = map(int, input().split())
mal = max(l1, l2)
mir = min(r1, r2)
if mir < mal:
	print(0)
else:
	d = mir - mal + 1
	if k >= mal and k <= mir:
		d -= 1
	print(d)


import sys
(l1, r1, l2, r2, k) = map(int, sys.stdin.readline().strip().split())
(l, r) = (max(l1, l2), min(r1, r2))
print(0 if l > r else r - l + 1 - (l <= k <= r))


(l1, r1, l2, r2, k) = map(int, input().split())
a = max(l1, l2)
b = min(r1, r2)
if b < a:
	print(0)
else:
	m = b - a + 1
	if k >= a and k <= b:
		m -= 1
	print(m)


(l1, r1, l2, r2, k) = map(int, input().split())
m = max(l1, l2)
n = min(r1, r2)
if n >= m:
	if k in range(m, n + 1):
		print(n + 1 - m - 1)
	else:
		print(n + 1 - m)
else:
	print('0')


(l1, r1, l2, r2, k) = list(map(int, input().split()))
if l1 >= l2 and r1 <= r2:
	if l1 <= k and r1 >= k:
		print(r1 - l1)
	else:
		print(r1 - l1 + 1)
elif l2 >= l1 and r2 <= r1:
	if l2 <= k and r2 >= k:
		print(r2 - l2)
	else:
		print(r2 - l2 + 1)
elif l1 <= l2 and l2 <= r1 and (r1 <= r2):
	if l2 <= k and r1 >= k:
		print(r1 - l2)
	else:
		print(r1 - l2 + 1)
elif l2 <= l1 and l1 <= r2 and (r2 <= r1):
	if l1 <= k and r2 >= k:
		print(r2 - l1)
	else:
		print(r2 - l1 + 1)
else:
	print(0)


import sys
from collections import Counter
from math import factorial
input = sys.stdin
output = sys.stdout

def read_int():
	return [int(x) for x in input.readline().rstrip().split()]
(l1, r1, l2, r2, k) = read_int()
l = max(l1, l2)
r = min(r1, r2)
answer = r - l + 1
if l <= k <= r:
	answer -= 1
answer = max(answer, 0)
output.write('%d\n' % answer)


(s_begin, s_end, f_begin, f_end, k) = map(int, input().split())
begin = max(s_begin, f_begin)
end = min(s_end, f_end)
minutes = 0
if begin > end:
	minutes = 0
elif begin <= k <= end:
	minutes = end - begin
else:
	minutes = end - begin + 1
print(minutes)


(a, b, c, d, e) = map(int, input().split())
l = max(a, c)
s = min(b, d)
if s < l:
	print(0)
elif l <= e <= s:
	print(s - l)
else:
	print(s - l + 1)


(l1, r1, l2, r2, k) = (int(x) for x in input().split())
if l2 > r1 or r2 < l1:
	print(0)
else:
	minima = min(r1, r2)
	maxima = max(l1, l2)
	ans = -maxima + minima + 1
	if k <= minima and k >= maxima:
		ans -= 1
	print(ans)


(l1, r1, l2, r2, k) = map(int, input().split(' '))
c = 0
l = max(l1, l2)
r = min(r1, r2)
if l <= r:
	if k in range(l, r + 1):
		print(r - l)
	else:
		print(r - l + 1)
else:
	print('0')


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


line = input()
l = line.split()
l1 = int(l[0])
r1 = int(l[1])
l2 = int(l[2])
r2 = int(l[3])
k = int(l[4])
spent = 0
if l2 > r1 or r2 < l1:
	spent = 0
else:
	if l1 > l2:
		start = l1
	else:
		start = l2
	if r1 < r2:
		finish = r1
	else:
		finish = r2
	spent = finish - start + 1
	if k >= start and k <= finish:
		spent -= 1
print(spent)


(l1, r1, l2, r2, k) = map(int, input().split())
x = max(l1, l2)
y = min(r1, r2)
res = y - x + 1
if y < x:
	print(0)
	exit()
elif k == x or k == y or (k > x and k < y):
	print(res - 1)
else:
	print(res)


(l1, r1, l2, r2, k) = map(int, input().split())
starting = max(l1, l2)
ending = min(r1, r2)
if starting > ending:
	print(0)
elif starting <= k <= ending:
	print(ending - starting)
else:
	print(ending - starting + 1)


def solve():
	(l1, r1, l2, r2, k) = list(map(int, input().split(' ')))
	start = max(l1, l2)
	end = min(r1, r2)
	ans = max(0, end - start + 1)
	if start <= k <= end:
		ans -= 1
	print(ans)

def main():
	solve()

def __starting_point():
	main()
__starting_point()


(l1, r1, l2, r2, k) = map(int, input().split())
if l2 < l1:
	if r2 < l1:
		print(0)
	else:
		if r2 < r1:
			start = l1
			end = r2
		else:
			start = l1
			end = r1
		if k >= start and k <= end:
			print(end - start)
		else:
			print(end - start + 1)
elif l2 > r1:
	print(0)
else:
	if r2 < r1:
		start = l2
		end = r2
	else:
		start = l2
		end = r1
	if k >= start and k <= end:
		print(end - start)
	else:
		print(end - start + 1)


(l1, r1, l2, r2, k) = [int(i) for i in input().split()]
if l1 <= l2 and l2 <= r1 and (r1 <= r2):
	s = r1 - l2 + 1
	if l2 <= k and k <= r1:
		s -= 1
if l2 <= l1 and l1 <= r2 and (r2 <= r1):
	s = r2 - l1 + 1
	if l1 <= k and k <= r2:
		s -= 1
if l1 <= r1 and r1 < l2 and (l2 <= r2):
	s = 0
if l2 <= r2 and r2 < l1 and (l1 <= r1):
	s = 0
if l2 <= l1 and l1 <= r1 and (r1 <= r2):
	s = r1 - l1 + 1
	if l1 <= k and k <= r1:
		s -= 1
if l1 <= l2 and l2 <= r2 and (r2 <= r1):
	s = r2 - l2 + 1
	if l2 <= k and k <= r2:
		s -= 1
print(s)


(l1, r1, l2, r2, k) = map(int, input().split())
l = max(l1, l2)
r = min(r1, r2)
t = r - l + 1
p = 0
if t < 0:
	p = 0
else:
	p = t
if p > 0 and k >= l and (k <= r):
	p -= 1
print(p)


(l1, r1, l2, r2, k) = map(int, input().split())
z = max(l1, l2)
x = min(r1, r2)
if z > x:
	print(0)
else:
	l = x - z + 1
	if k >= z and k <= x:
		l = l - 1
	print(l)


(l, r, l1, r1, d) = map(int, input().split())
ans = 0
ans += min(r, r1) - max(l, l1)
if ans < 0:
	ans = 0
else:
	ans += 1
if d >= max(l, l1) and d <= min(r, r1):
	ans -= 1
print(ans)


(a, b, c, d, k) = map(int, input().split())
l = max(a, c)
r = min(b, d)
if l > r:
	print(0)
else:
	ans = abs(l - r) + 1
	if l <= k <= r:
		print(ans - 1)
	else:
		print(ans)


(l1, r1, l2, r2, k) = map(int, input().split())
lm = max(l1, l2)
rm = min(r1, r2)
if lm > rm:
	print(0)
elif lm <= k <= rm:
	print(rm - lm)
else:
	print(rm - lm + 1)


import sys
import math
import bisect

def main():
	(l1, r1, l2, r2, k) = map(int, input().split())
	l = max(l1, l2)
	r = min(r1, r2)
	if l <= r:
		ans = r - l + 1
		if k >= l and k <= r:
			ans -= 1
	else:
		ans = 0
	print(ans)
main()


(l1, r1, l2, r2, k) = str(input()).split()
l1 = int(l1)
r1 = int(r1)
l2 = int(l2)
r2 = int(r2)
k = int(k)
if r1 < l2 or r2 < l1:
	print(0)
else:
	min_r = min(r1, r2)
	max_l = max(l1, l2)
	if max_l <= k <= min_r:
		print(min_r - max_l)
	else:
		print(1 + min_r - max_l)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
(l1, r1, l2, r2, k) = ilele()
if r2 < l1 or l2 > r1:
	print(0)
else:
	a = max(l1, l2)
	b = min(r1, r2)
	c = b - a + 1
	if a <= k <= b:
		c -= 1
	print(c)


def f(l):
	(l1, r1, l2, r2, k) = l
	l = max(l1, l2)
	r = min(r1, r2)
	if r < l:
		return 0
	return r - l + 1 if k < l or k > r else r - l
l = list(map(int, input().split()))
print(f(l))


a = list(map(int, input().split()))
if a[0] >= a[2]:
	d = a[0]
else:
	d = a[2]
if a[1] >= a[3]:
	e = a[3]
else:
	e = a[1]
f = e - d + 1
if a[4] >= d and e >= a[4]:
	f -= 1
if f < 0:
	print('0')
else:
	print(f)


(l1, r1, l2, r2, k) = map(int, input().split())
a = max(l1, l2)
b = min(r1, r2)
print(max(0, b - a + 1 - (a <= k <= b)))


(a, b, c, d, k) = map(int, input().split())
mx = max(a, c)
mn = min(b, d)
ans = mn - mx + 1
if mx <= k <= mn:
	ans -= 1
print(max(ans, 0))


(l1, r1, l2, r2, k) = list(map(int, input().strip().split(' ')))
if l1 >= l2 and l1 <= r2 or (r1 >= l2 and r1 <= r2) or (l2 >= l1 and l2 <= r1) or (r2 >= l1 and r2 <= r1):
	a = max(l1, l2)
	b = min(r1, r2)
	ans = b - a + 1
	if a <= k and b >= k:
		ans -= 1
	print(ans)
	exit(0)
print(0)


(l1, r1, l2, r2, k) = map(int, input().split())
maxl = max(l1, l2)
minr = min(r1, r2)
if maxl > minr:
	print(0)
elif maxl <= k <= minr:
	print(minr - maxl)
else:
	print(minr - maxl + 1)


(l1, r1, l2, r2, k) = map(int, input().split())
res = min(r1, r2) - max(l1, l2) + 1
if res < 0:
	res = 0
if max(l1, l2) <= k <= min(r1, r2):
	res -= 1
print(res)


(s_time1, s_time2, f_time1, f_time2, p_time) = map(int, input().split(' '))
timeset = []
timeset.append(max(s_time1, f_time1))
timeset.append(min(s_time2, f_time2))
time = timeset[1] + 1 - timeset[0]
if p_time >= timeset[0] and p_time <= timeset[1]:
	time -= 1
if time < 0:
	time = 0
print(time)


inputLine = input()
lineSplit = inputLine.split()
sonyaStart = int(lineSplit[0])
sonyaEnd = int(lineSplit[1])
filyaStart = int(lineSplit[2])
filyaEnd = int(lineSplit[3])
sonyaPlink = int(lineSplit[4])
if sonyaStart <= filyaStart:
	if sonyaEnd < filyaStart:
		meetingTime = 0
	elif filyaEnd < sonyaEnd:
		meetingTime = filyaEnd - filyaStart + 1
		if sonyaPlink in range(filyaStart, filyaEnd + 1):
			meetingTime -= 1
	else:
		meetingTime = sonyaEnd - filyaStart + 1
		if sonyaPlink in range(filyaStart, sonyaEnd + 1):
			meetingTime -= 1
elif filyaStart <= sonyaStart:
	if filyaEnd < sonyaStart:
		meetingTime = 0
	elif sonyaEnd < filyaEnd:
		meetingTime = sonyaEnd - sonyaStart + 1
		if sonyaPlink in range(filyaStart, sonyaEnd + 1):
			meetingTime -= 1
	else:
		meetingTime = filyaEnd - sonyaStart + 1
		if sonyaPlink in range(sonyaStart, filyaEnd + 1):
			meetingTime -= 1
print(meetingTime)


(l1, r1, l2, r2, k) = map(int, input().split())
startTime = max(l1, l2)
endTime = min(r1, r2)
ans = endTime - startTime + 1
if k >= startTime and k <= endTime:
	ans -= 1
print(max(0, ans))


import sys, math
(l1, r1, l2, r2, k) = map(int, input().split())
a = max(l1, l2)
b = min(r1, r2)
ans = b - a + 1
if a <= k <= b:
	ans -= 1
print(max(0, ans))


(l1, r1, l2, r2, k) = (int(z) for z in input().split())
L = max(l1, l2)
R = min(r1, r2)
ans = 0
if L <= k <= R:
	ans -= 1
print(max(ans + R - L + 1, 0))


def inp():
	return map(int, input().split())
(l1, r1, l2, r2, k) = inp()
(out, start, end) = (0, max(l1, l2), min(r1, r2))
if start <= end:
	out += end - start
	if k < start or k > end:
		out += 1
print(out)


(l, r, l1, r1, k) = map(int, input().split())
arr = [l, l1]
arr1 = [r, r1]
arr.sort()
arr1.sort()
left = arr[1]
right = arr1[0]
ans = right - left + 1
if left <= k <= right:
	ans -= 1
print(max(ans, 0))


s = input().split()
for i in range(0, 5):
	s[i] = int(s[i])
low = max(s[0], s[2])
high = min(s[1], s[3])
ans = high - low + 1
if low <= s[4] and s[4] <= high:
	ans -= 1
ans = max(ans, 0)
print(ans)


(l1, r1, l2, r2, k) = [int(x) for x in input().split()]
l = max(l1, l2)
r = min(r1, r2)
time = r - l + 1
if time <= 0:
	print(0)
else:
	if l <= k <= r:
		time -= 1
	print(time)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
(l1, r1, l2, r2, k) = mapi()
res = max(0, min(r1, r2) - max(l1, l2) + 1)
if min(r1, r2) >= k >= max(l1, l2):
	res -= 1
print(res)


(l1, r1, l2, r2, k) = [int(i) for i in input().split()]
result = -1
if l2 > r1 or r2 < l1:
	result = 0
elif l2 >= l1 and r2 <= r1:
	result = r2 - l2 + 1
	if k >= l2 and k <= r2:
		result -= 1
elif l1 >= l2 and r1 <= r2:
	result = r1 - l1 + 1
	if k >= l1 and k <= r1:
		result -= 1
elif l2 >= l1 and r2 >= r1:
	result = r1 - l2 + 1
	if k >= l2 and k <= r1:
		result -= 1
else:
	result = r2 - l1 + 1
	if k >= l1 and k <= r2:
		result -= 1
print(result)


(l1, r1, l2, r2, k) = map(int, input().split())
t1 = max(l1, l2)
t2 = min(r1, r2)
if k >= t1 and k <= t2:
	print(t2 - t1)
elif t2 - t1 + 1 >= 0:
	print(t2 - t1 + 1)
else:
	print('0')


(l1, r1, l2, r2, k) = [int(i) for i in input().split()]
if l1 > r2 or l2 > r1:
	print(0)
else:
	start = max(l1, l2)
	end = min(r1, r2)
	if start <= k <= end:
		print(end - start)
	else:
		print(end - start + 1)


(l1, r1, l2, r2, k) = list(map(int, input().split()))
start = max(l1, l2)
end = min(r1, r2)
c = end - start + 1
if k in range(start, end + 1):
	c -= 1
if c < 0:
	c = 0
print(c)


(l, r, l1, r2, k) = map(int, input().split())
if l1 > r or l > r2:
	print(0)
else:
	print(min(r, r2) - max(l, l1) + 1 - (0, 1)[k >= max(l, l1) and k <= min(r, r2)])


def main():
	(l1, r1, l2, r2, k) = map(int, input().split())
	(l1, r1) = (max(l1, l2), min(r1, r2))
	print(r1 - l1 + (not l1 <= k <= r1) if l1 <= r1 else 0)
main()


(l1, r1, l2, r2, k) = map(int, input().split())
a = [[l1, -1], [r1, 1], [l2, -1], [r2, 1]]
bal = 0
a.sort()
begin = 0
end = -1
for elem in a:
	if bal == 1 and elem[1] == -1:
		begin = elem[0]
	if bal == 2:
		end = elem[0]
	bal -= elem[1]
if begin <= k <= end:
	end -= 1
print(max(0, end - begin + 1))


def go():
	(l1, r1, l2, r2, k) = tuple(map(lambda x: int(x), input().split()))
	if l1 > r2 or l2 > r1:
		print(0)
		return
	l = min(l2, l1) + abs(l2 - l1)
	r = max(r2, r1) - abs(r2 - r1)
	if k >= l and k <= r:
		print(r - l)
	else:
		print(r - l + 1)
go()


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(l1, r1, l2, r2, k) = value()
if l1 > r2 or r1 < l2:
	print(0)
else:
	S = (l1, r1)
	R = (l2, r2)
	(S, R) = sorted((S, R))
	low = R[0]
	high = min(S[1], R[1])
	ans = high - low + 1
	if low <= k <= high:
		ans -= 1
	print(ans)


(l1, r1, l2, r2, k) = map(int, input().split())
if l1 < l2:
	a = l2
else:
	a = l1
if r1 < r2:
	b = r1
else:
	b = r2
s = b - a + 1
if k >= a and k <= b:
	s -= 1
if l2 < l1 and r2 < l1 or (l2 > r1 and r2 > r1):
	s = 0
print(s)


from math import *
(a, b, c, d, k) = map(int, input().split())
per1 = max(a, c)
per2 = min(b, d)
if per2 >= per1:
	if per1 <= k <= per2:
		print(per2 - per1)
	else:
		print(per2 - per1 + 1)
else:
	print(0)


def overlapping_time(time_frames):
	start = max(time_frames[0], time_frames[2])
	stop = min(time_frames[1], time_frames[3])
	return (start, stop)

class CodeforcesTask714ASolution:

	def __init__(self):
		self.result = ''
		self.l1_r1_l2_r2_k = []

	def read_input(self):
		self.l1_r1_l2_r2_k = [int(x) for x in input().split(' ')]

	def process_task(self):
		(st, sp) = overlapping_time(self.l1_r1_l2_r2_k[:4])
		time = sp - st + 1
		if st <= self.l1_r1_l2_r2_k[4] <= sp:
			time -= 1
		if time > 0:
			self.result = str(time)
		else:
			self.result = '0'

	def get_result(self):
		return self.result
Solution = CodeforcesTask714ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(l1, r1, l2, r2, k) = map(int, input().split())
if l1 <= l2 and r2 <= r1:
	if k in range(l2, r2 + 1):
		print(r2 - l2)
	else:
		print(max(0, r2 - l2 + 1))
elif l1 <= l2 and l2 <= r1 and (r2 > r1):
	if k in range(l2, r1 + 1):
		print(r1 - l2)
	else:
		print(max(0, r1 - l2 + 1))
elif l1 >= l2 and r2 <= r1:
	if k in range(l1, r2 + 1):
		print(r2 - l1)
	else:
		print(max(0, r2 - l1 + 1))
elif l1 > r2 or l2 > r1 or r1 < l2:
	print(0)
elif l1 >= l2 and r2 >= r1:
	if k in range(l1, r1 + 1):
		print(r1 - l1)
	else:
		print(max(0, r1 - l1 + 1))


a = input().split()
l1 = int(a[0])
r1 = int(a[1])
l2 = int(a[2])
r2 = int(a[3])
k = int(a[4])
l = max(l1, l2)
r = min(r1, r2)
if l > r:
	print('0')
else:
	ans = r - l + 1
	if k <= r and k >= l:
		ans -= 1
	print(ans)


(l1, r1, l2, r2, k) = input().split()
min = int(l1) if int(l1) > int(l2) else int(l2)
max = int(r2) if int(r1) > int(r2) else int(r1)
rst = 0
if int(k) < min or int(k) > max:
	rst = max - min + 1
else:
	rst = int(k) - 1 - min + max - int(k) + 1
if rst < 0:
	print(0)
else:
	print(rst)


(l1, r1, l2, r2, k) = map(int, input().split())
(mi, ma) = (max(l1, l2), min(r1, r2))
if mi <= k <= ma:
	print(0 if ma - mi < 0 else ma - mi)
else:
	print(0 if ma - mi < 0 else ma - mi + 1)


(l1, r1, l2, r2, k) = map(int, input().split())
c = 0
if l2 >= l1 and r2 <= r1:
	c = c + r2 - l2 + 1
	if l2 <= k <= r2:
		c = c - 1
elif l2 < l1 and r2 < l1:
	c = c + 0
elif l2 > r1:
	c = c + 0
elif l2 >= l1 and r2 > r1:
	c = c + r1 - l2 + 1
	if l2 <= k <= r1:
		c = c - 1
elif l2 <= l1 and r2 >= r1:
	c = c + r1 - l1 + 1
	if l1 <= k <= r1:
		c = c - 1
elif l2 <= l1 and r2 <= r1:
	c = c + r2 - l1 + 1
	if l1 <= k <= r2:
		c = c - 1
elif l2 == r2:
	c = c + 1
	if k == l2 or k == r2:
		c = c - 1
elif l2 > r2:
	c = c + 0
print(c)


def intersect(l1, r1, l2, r2):
	if l1 > l2:
		(l1, r1, l2, r2) = (l2, r2, l1, r1)
	if r1 < l2:
		return (None, None)
	if r2 <= r1:
		return (l2, r2)
	return (l2, r1)

def solve(l1, r1, l2, r2, k):
	(l, r) = intersect(l1, r1, l2, r2)
	if l is None:
		return 0
	if l <= k <= r:
		return r - l
	else:
		return r - l + 1
(l1, r1, l2, r2, k) = map(int, input().split())
print(solve(l1, r1, l2, r2, k))


(l1, r1, l2, r2, k) = [int(x) for x in input().split()]
end = min(r1, r2)
start = max(l1, l2)
ans = end - start + 1
ans -= 1 if start <= k <= end else 0
print(max(0, ans))


(r1, l1, r2, l2, k) = map(int, input().split())
p1 = max(r1, r2)
p2 = min(l1, l2)
p = p2 - p1 + 1
if k >= p1 and k <= p2:
	p -= 1
if p < 0:
	p = 0
print(p)


[l1, r1, l2, r2, k] = list(map(int, input().split()))
res = 0
l3 = l1
r3 = min(r1, k - 1)
if l3 <= r3:
	res += max(0, min(r2, r3) - max(l2, l3) + 1)
l4 = max(l1, k + 1)
r4 = r1
if l4 <= r4:
	res += max(0, min(r2, r4) - max(l2, l4) + 1)
print(res)


import sys
(l1, r1, l2, r2, k) = map(int, sys.stdin.readline().split())
ans = 0
l = max(l1, l2)
r = min(r1, r2)
if l <= r:
	ans = r - l + 1
	if l <= k and k <= r:
		ans -= 1
print(ans)


def meeting_old_friends():
	data = [int(x) for x in input().strip().split(' ')]
	l = max(data[0], data[2])
	r = min(data[1], data[3])
	if l > r:
		print(0)
	elif data[4] <= r and data[4] >= l:
		print(r - l)
	else:
		print(r - l + 1)
meeting_old_friends()


def run():
	input_line = input().split(' ')
	sonya_awake_from = int(input_line[0])
	sonya_awake_to = int(input_line[1])
	planned_visit_from = int(input_line[2])
	planned_visit_to = int(input_line[3])
	prinking_time = int(input_line[4])
	visit_start_inklusive = planned_visit_from if planned_visit_from > sonya_awake_from else sonya_awake_from
	visit_end_inklusive = planned_visit_to if planned_visit_to < sonya_awake_to else sonya_awake_to
	visit_end_exclusive = visit_end_inklusive + 1
	visit_time = visit_end_exclusive - visit_start_inklusive - (1 if visit_start_inklusive <= prinking_time <= visit_end_inklusive else 0)
	print(visit_time if visit_time > 0 else 0)
run()


l = list(map(int, input().split()))
edge = (max(l[0], l[2]), min(l[1], l[3]))
ans = edge[1] - edge[0] + 1
if l[4] >= edge[0] and l[4] <= edge[1]:
	ans -= 1
if ans < 0:
	ans = 0
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
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 [tuple(map(int, l.split())) for l in sys.stdin]

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 main():
	(a, b, c, d, e) = LI()
	f = max(a, c)
	g = min(b, d)
	if f > g:
		return 0
	r = g - f + 1
	if f <= e <= g:
		r -= 1
	return r
print(main())


(a, b, x, y, m) = map(int, input().split())
x = max(a, x)
y = 1 + min(b, y)
print(max(0, y - x - (x <= m < y)))


inp = input().split()
inp = list(map(int, inp))
(l1, r1, l2, r2, k) = inp
if r1 < l2 or r2 < l1:
	print('0')
else:
	a = max(l1, l2)
	b = min(r1, r2)
	ans = b - a + 1
	if a <= k and k <= b:
		ans = ans - 1
	print(ans)


time_interval = list(map(int, input().split()))
l1 = time_interval[0]
r1 = time_interval[1]
l2 = time_interval[2]
r2 = time_interval[3]
k = time_interval[4]
time = 0
l = max(l1, l2)
r = min(r1, r2)
if l > r:
	time = 0
elif k >= l and k <= r:
	time = r - l
else:
	time = r - l + 1
print(time)


x = input().split()
l1 = int(x[0])
r1 = int(x[1])
l2 = int(x[2])
r2 = int(x[3])
k = int(x[4])
left = max(l1, l2)
right = min(r1, r2)
if left > right:
	print(0)
elif left <= k <= right:
	print(right - left)
else:
	print(right - left + 1)


from io import BytesIO, IOBase
import sys
import math
import os
from collections import defaultdict
from math import ceil
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

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

def mfloat():
	return map(float, input().split())

def solve():
	(l1, r1, l2, r2, k) = mint()
	intersection_start = max(l1, l2)
	intersection_end = min(r1, r2)
	time = intersection_end - intersection_start - (intersection_start <= k <= intersection_end)
	print(max(time + 1, 0))

def main():
	t = 1
	for _ in range(t):
		solve()
main()


(l1, r1, l2, r2, k) = list(map(int, input().split()))
a = b = -1
if l1 <= l2 and r2 <= r1:
	(a, b) = (l2, r2)
elif l2 <= l1 and r1 <= r2:
	(a, b) = (l1, r1)
elif l1 <= l2 <= r1:
	(a, b) = (l2, r1)
elif l1 <= r2 <= r1:
	(a, b) = (l1, r2)
if a == -1 or b == -1:
	print(0)
else:
	res = b - a + 1
	if a <= k <= b:
		res -= 1
	print(res)


data = input().split()
g = [int(x) for x in data]
l1 = g[0]
r1 = g[1]
l2 = g[2]
r2 = g[3]
k = g[4]
l = max(l1, l2)
r = min(r1, r2)
if l > r:
	print(0)
elif k >= l and r >= k:
	print(r - l)
else:
	print(r - l + 1)


[l1, r1, l2, r2, k] = [int(x) for x in input().split()]
l = max(l1, l2)
r = min(r1, r2)
c = r - l + 1
if k <= r and k >= l:
	c -= 1
if c < 0:
	c = 0
print(c)


(n, m, l, r, k) = map(int, input().split())
x = max(n, l)
y = min(m, r)
l = y - x + 1
if x <= k and k <= y:
	l -= 1
print(max(0, l))


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

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

def instr():
	s = input()
	return list(s[:len(s)])

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

def def_value():
	return 0
(l1, r1, l2, r2, k) = invr()
if r2 < l1 or l2 > r1:
	print(0)
	sys.exit()
L = max(l1, l2)
R = min(r1, r2)
res = R - L + 1
if k >= L and k <= R:
	res -= 1
if res < 0:
	print(0)
else:
	print(res)


(l1, r1, l2, r2, k) = [int(x) for x in input().split(' ')]
f = min(r2, r1)
s = max(l1, l2)
r = f - s + 1
if k >= s and k <= f:
	r -= 1
if r < 0:
	r = 0
print(r)


def btd(n):
	return int(n, 2)

def dtb(n):
	return bin(n).replace('0b', '')
import sys
input = sys.stdin.buffer.readline

def solve():
	(l1, r1, l2, r2, k) = map(int, input().split())
	if r1 < l2 or r2 < l1:
		print(0)
	elif l1 <= l2 <= r1 and r2 > r1:
		ans = r1 - l2 + 1
		if l2 <= k <= r1 and ans > 0:
			ans -= 1
		print(ans)
	elif l1 <= r2 <= r1 and l2 < l1:
		ans = r2 - l1 + 1
		if l1 <= k <= r2 and ans > 0:
			ans -= 1
		print(ans)
	elif l2 < l1 and r2 > r1:
		ans = r1 - l1 + 1
		if l1 <= k <= r1 and ans > 0:
			ans -= 1
		print(ans)
	else:
		ans = r2 - l2 + 1
		if l2 <= k <= r2 and ans > 0:
			ans -= 1
		print(ans)
solve()


s = input()
c = 0
r = s.split(' ')
mx = max(int(r[0]), int(r[2]))
mn = min(int(r[1]), int(r[3]))
if mx > mn:
	print(0)
elif int(r[4]) >= mx and int(r[4]) <= mn:
	c = mn - mx
	print(c)
else:
	c = mn - mx + 1
	print(c)


inp = list(map(int, input().split()))
l = max(inp[0], inp[2])
r = min(inp[1], inp[3])
res = max(r - l + 1, 0)
print(res - (l <= inp[4] <= r))


(x, y, a, b, k) = map(int, input().split())
xx = min(y, b)
yy = max(a, x)
if k >= yy and k <= xx:
	print(max(0, xx - yy))
else:
	print(max(0, xx - yy + 1))


X = list(map(int, input().split()))
First = max(X[0], X[2])
Last = min(X[1], X[3])
Answer = Last - First + 1
print(max(Answer, 0) if X[4] not in range(First, Last + 1) or Answer < 0 else Answer - 1)


(a, b, c, d, e) = input('').split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
z = 0
if a > d or c > b:
	print(0)
	exit()
if c > a:
	z = z + min(b, d) - c + 1
	if e >= c and e <= min(b, d):
		z = z - 1
else:
	z = z + min(b, d) - a + 1
	if e >= a and e <= min(b, d):
		z = z - 1
print(z)


(l1, r1, l2, r2, k) = map(int, input().split())
if l1 < l2:
	beginning = l2
else:
	beginning = l1
if r1 < r2:
	ending = r1
else:
	ending = r2
if beginning > ending:
	x = 0
elif beginning != ending:
	if k >= beginning and k <= ending:
		x = ending - beginning
	else:
		x = ending - beginning + 1
elif beginning == ending:
	if k == ending:
		x = 0
	else:
		x = 1
print(x)


(l1, r1, l2, r2, k) = map(int, input().split())
lmax = max(l1, l2)
rmin = min(r1, r2)
if lmax > rmin:
	print(0)
else:
	ans = rmin - lmax + 1
	if k >= lmax and k <= rmin:
		ans -= 1
	print(ans)


(l1, r1, l2, r2, k) = map(int, input().split())
if r1 < l2 or r2 < l1:
	print(0)
else:
	(st, end) = (max(l1, l2), min(r1, r2))
	if st <= k <= end:
		print(end - st)
	else:
		print(end - st + 1)


def meet_friends():
	times = list(map(int, input().split()))
	if times[2] > times[1] or times[3] < times[0]:
		return 0
	output = 0
	if times[2] > times[0]:
		if times[3] > times[1]:
			output += abs(times[1] - times[2]) + 1
			if times[4] >= times[2] and times[4] <= times[1]:
				output -= 1
		else:
			output += abs(times[3] - times[2]) + 1
			if times[4] >= times[2] and times[4] <= times[3]:
				output -= 1
	elif times[3] > times[1]:
		output += abs(times[1] - times[0]) + 1
		if times[4] >= times[0] and times[4] <= times[1]:
			output -= 1
	else:
		output += abs(times[3] - times[0]) + 1
		if times[4] >= times[0] and times[4] <= times[3]:
			output -= 1
	return output
A = meet_friends()
print(A)


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


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


(s1, e1, s2, e2, k) = map(int, input().split())
ans = min(e1, e2) - max(s1, s2) + 1
print(max(ans - 1, 0) if max(s1, s2) <= k <= min(e1, e2) else max(ans, 0))


(left1, right1, left2, right2, k) = map(int, input().split())
intersection_left = max(left1, left2)
intersection_right = min(right1, right2)
answer = 0
if intersection_right >= k >= intersection_left:
	answer -= 1
if intersection_right >= intersection_left:
	answer += intersection_right - intersection_left + 1
print(answer)


(a, b, n, m, k) = map(int, input().split())
L = max(a, n)
R = min(b, m)
t = R - L + 1
if L <= k <= R:
	t -= 1
print(max(t, 0))


(l, r, L, R, k) = map(int, input().split())
l = max(l, L)
r = min(r, R)
ans = r - l + 1
if l <= k and k <= r:
	ans -= 1
print(max(ans, 0))


(l1, r1, l2, r2, k) = map(int, input().split())
ans = 0
if l1 >= l2 and r1 <= r2:
	ans = r1 - l1 + 1
	if l1 <= k <= r1:
		ans -= 1
elif l2 >= l1 and r2 <= r1:
	ans = r2 - l2 + 1
	if l2 <= k <= r2:
		ans -= 1
elif l1 >= l2 and r2 >= l1:
	ans = r2 - l1 + 1
	if l1 <= k <= r2:
		ans -= 1
elif l1 < l2 and l2 <= r1:
	ans = r1 - l2 + 1
	if l2 <= k <= r1:
		ans -= 1
print(ans)


(l1, r1, l2, r2, k) = map(int, input().split())
a = max(l1, l2)
b = min(r1, r2)
c = b - a + 1
if k >= a and k <= b:
	c -= 1
if c < 0:
	print(0)
	exit()
print(c)


(l1, r1, l2, r2, k) = map(int, input().split())
s = 0
if l2 >= l1 and l2 <= r1:
	s = min(r1, r2) - l2 + 1
	if k >= l2 and k <= min(r1, r2):
		s -= 1
elif l2 < l1:
	if r2 >= l1:
		s = min(r1, r2) - l1 + 1
		if k >= l1 and k <= min(r1, r2):
			s -= 1
print(s)


(l1, r1, l2, r2, k) = map(int, input().split())
if l1 < l2:
	l1 = l2
else:
	l2 = l1
if r1 < r2:
	r2 = r1
else:
	r1 = r2
result = r1 - l2 + 1
if l2 <= k <= r1:
	result -= 1
print(result if result > 0 else 0)


import math
(l1, r1, l2, r2, k) = map(int, input().split())
l = max(l1, l2)
r = min(r1, r2)
if l > r:
	print(0)
else:
	print(r - l + 1 - (k <= r and k >= l))


a = [int(x) for x in input().split()]
k = a[4]
if a[2] > a[1] or a[0] > a[3]:
	print('0')
	exit()
l = max(a[0], a[2])
r = min(a[1], a[3])
if k >= l and k <= r:
	print(r - l)
else:
	print(r - l + 1)


(l1, r1, l2, r2, k) = map(int, input().split())
tmp = max(min(r1, r2) - max(l1, l2) + 1, 0)
if k >= max(l1, l2) and k <= min(r1, r2):
	tmp -= 1
print(tmp)


from sys import stdout
(a, b, c, d, e) = [int(i) for i in input().split()]
t = max(a, c)
t1 = min(b, d)
if t <= t1:
	if t <= e and e <= t1:
		print(t1 - t)
	else:
		print(t1 - t + 1)
else:
	print(0)


inp = input().split(' ')
for i in range(0, 5):
	inp[i] = int(inp[i])
a = max(inp[0], inp[2])
b = min(inp[1], inp[3])
if inp[4] in range(a, b + 1):
	print(max(b - a, 0))
else:
	print(max(b - a + 1, 0))


(l1, r1, l2, r2, k) = map(int, input().split())
l3 = 0
r3 = 0
c = 0
if r3 == 0:
	if l2 < l1:
		l3 = l1
	else:
		l3 = l2
if r3 == 0:
	if r2 > r1:
		r3 = r1
	else:
		r3 = r2
c = r3 - l3 + 1
if k >= l3 and k <= r3:
	c = c - 1
if c < 0:
	print(0)
else:
	print(c)


(l1, r1, l2, r2, k) = (int(x) for x in input().split())
answer = -1
if l1 > r2:
	answer = 0
elif l2 > r1:
	answer = 0
elif l1 <= l2 and r2 <= r1:
	themin = l2
	themax = r2
elif l2 <= l1 and r1 <= r2:
	themin = l1
	themax = r1
elif l2 >= l1 and l2 <= r1:
	themin = l2
	themax = r1
elif l1 >= l2 and l1 <= r2:
	themin = l1
	themax = r2
if answer == -1:
	if themin <= k and k <= themax:
		answer = themax - themin
	else:
		answer = themax - themin + 1
print(answer)


i = input().split()
start = max(int(i[0]), int(i[2]))
end = min(int(i[1]), int(i[3]))
res = end - start + 1
if start <= int(i[4]) <= end:
	res -= 1
if res < 0:
	res = 0
print(res)


from sys import stdin
(l1, r1, l2, r2, k) = (int(x) for x in stdin.readline().split())
l = max(l1, l2)
r = min(r1, r2)
result = r - l + 1
if l <= k <= r:
	result -= 1
print(max(result, 0))


(l1, r1, l2, r2, k) = map(int, input().split())
if l1 > r2 or r1 < l2:
	print(0)
	exit(0)
ml = max(l1, l2)
mr = min(r1, r2)
delta = 1 if ml <= k <= mr else 0
print(abs(mr - ml) + 1 - delta)


from collections import defaultdict
import sys, os, math
(l1, r1, l2, r2, k) = map(int, input().split())
if l1 > r2 or l2 > r1:
	print(0)
	sys.exit(0)
(l, r) = (max(l1, l2), min(r1, r2))
if k >= l and k <= r:
	print(r - l)
else:
	print(r - l + 1)


(l1, r1, l2, r2, k) = map(int, input().split())
ll = max(l1, l2)
rr = min(r1, r2)
count = 0
if ll > rr:
	count = 0
else:
	count = rr - ll + 1
	if k >= ll and k <= rr:
		count -= 1
print(count)


(l1, r1, l2, r2, k) = [int(x) for x in input().split()]
if max(l1, l2) > min(r1, r2):
	print(0)
else:
	res = min(r1, r2) - max(l1, l2) + 1
	if k <= min(r1, r2) and k >= max(l1, l2):
		res -= 1
	print(res)


(l1, r1, l2, r2, k) = input().strip().split(' ')
(l1, r1, l2, r2, k) = (int(l1), int(r1), int(l2), int(r2), int(k))
if max(l1, l2) > min(r1, r2):
	print(0)
elif max(l1, l2) <= k and k <= min(r1, r2):
	print(min(r1, r2) - max(l1, l2))
else:
	print(min(r1, r2) - max(l1, l2) + 1)


from sys import stdin

def main():
	(l1, r1, l2, r2, k) = stdin_get_ints_from_line()
	(t1, t2) = (max(l1, l2), min(r1, r2))
	tt = 0
	if t1 <= k <= t2:
		tt = 1
	if t2 < t1:
		print(0)
		exit()
	r = t2 - t1 - tt + 1
	print(r)
	return

def stdin_get_ints_from_line():
	return (int(x) for x in stdin.readline().strip().split(' '))

def stdin_get_ints_list_from_line():
	return list((int(x) for x in stdin.readline().strip().split(' ')))

def stdin_get_string_from_line():
	return stdin.readline().strip()
main()


import sys
input = sys.stdin.buffer.readline
(l1, r1, l2, r2, k) = map(int, input().split())
p1 = 0
p2 = 0
if r2 < l1 or l2 > r1:
	p1 = -1
	p2 = -1
elif l2 >= l1 and r2 <= r1:
	p1 = l2
	p2 = r2
elif l2 >= l1 and r2 > r1:
	p1 = l2
	p2 = r1
elif r2 <= r1 and l2 < l1:
	p1 = l1
	p2 = r2
else:
	p1 = l1
	p2 = r1
if p1 == -1 and p2 == -1:
	print('0')
elif k >= p1 and k <= p2:
	print(p2 - p1)
else:
	print(p2 - p1 + 1)


(l_1, r_1, l_2, r_2, k) = map(int, input().split())
left = max(l_1, l_2)
right = min(r_1, r_2)
if left > right:
	print(0)
elif left <= k <= right:
	print(right - left)
else:
	print(right - left + 1)


(l1, r1, l2, r2, k) = map(int, input().strip().split())
if l2 > r1 or r2 < l1:
	rez = 0
elif r2 >= r1 and l1 >= l2:
	rez = r1 - l1 + 1
	if k >= l1 and k <= r1:
		rez -= 1
elif r1 >= r2 and l1 <= l2:
	rez = r2 - l2 + 1
	if k <= r2 and k >= l2:
		rez -= 1
elif r1 >= r2 and l1 >= l2:
	rez = r2 - l1 + 1
	if k >= l1 and k <= r2:
		rez -= 1
else:
	rez = r1 - l2 + 1
	if k >= l2 and k <= r1:
		rez -= 1
if rez > 0:
	print(rez)
else:
	print(0)


read = lambda : list(map(int, input().split()))
(l1, r1, l2, r2, k) = read()
R = min(r1, r2)
L = max(l1, l2)
ans = max(R - L + 1, 0)
if L <= k <= R:
	ans = max(ans - 1, 0)
print(ans)


(l1, r1, l2, r2, k) = input().split()
left = max(int(l1), int(l2))
right = min(int(r1), int(r2))
if right - left >= 0:
	if left <= int(k) <= right:
		print(right - left)
	else:
		print(right - left + 1)
else:
	print(0)


def main():
	(l1, r1, l2, r2, k) = input().strip().split(' ')
	answ = min(int(r1), int(r2)) - max(int(l1), int(l2)) + 1
	if int(k) >= max(int(l1), int(l2)) and int(k) <= min(int(r1), int(r2)):
		answ -= 1
	if answ <= 0:
		print(0)
	else:
		print(answ)
main()


import sys
(l1, r1, l2, r2, k) = [int(x) for x in input().split()]
l = max(l1, l2)
r = min(r1, r2)
if l > r:
	print(0)
elif k <= r and l <= k:
	print(r - l)
else:
	print(r - l + 1)


(l1, r1, l2, r2, k) = map(int, input().split())
(a, b) = (min(r1, r2), max(l1, l2))
res = a - b
if res < 0:
	print(0)
elif a >= k >= b:
	print(res)
else:
	print(res + 1)


(l1, r1, l2, r2, k) = list(map(int, input().split()))
s1 = max(l1, l2)
s2 = min(r1, r2)
ans = 0
if s1 > s2:
	ans = 0
elif s1 <= k <= s2:
	ans = s2 - s1
else:
	ans = s2 - s1 + 1
print(ans)


import sys
(l1, r1, l2, r2, k) = map(int, sys.stdin.readline().strip().split())
if l2 > r1:
	print(0)
elif l1 <= l2 <= r1:
	print(min(r1, r2) - l2 + 1 - (l2 <= k <= min(r1, r2)))
elif l2 < l1:
	if r2 < l1:
		print(0)
	else:
		print(min(r1, r2) - l1 + 1 - (l1 <= k <= min(r1, r2)))


(l1, r1, l2, r2, k) = map(int, input().split())
tp = ((l1, r1), (l2, r2))
tp = sorted(tp)
((l1, r1), (l2, r2)) = (tp[0], tp[1])
if l1 <= l2 and r2 <= r1:
	p = [l2, r2]
	(r1, r2) = sorted(p)
	if r1 <= k <= r2:
		print(r2 - r1)
	else:
		print(r2 - r1 + 1)
elif l1 <= l2 <= r1:
	p = [r1, l2]
	(r1, r2) = sorted(p)
	if r1 <= k <= r2:
		print(r2 - r1)
	else:
		print(r2 - r1 + 1)
else:
	print(0)


I = lambda : map(int, input().split())
(l1, r1, l2, r2, k) = I()
ans = 0
if l1 <= r2 and l2 <= r1:
	a = sorted([l1, r1, l2, r2])
	ans = a[2] - a[1] + 1
	if a[1] <= k <= a[2]:
		ans -= 1
print(ans)


a = list(map(int, input().split()))
k = a[-1]
del a[-1]
if a[0] > a[3] or a[2] > a[1]:
	print(0)
else:
	a.sort()
	print(a[2] - a[1] + 1 - int(a[1] <= k and k <= a[2]))


(l1, r1, l2, r2, k) = map(int, input().split())
mac = max(l1, l2)
mia = min(r1, r2)
ans = mia - mac + 1
if k >= mac and k <= mia:
	ans = ans - 1
if ans > 0:
	print(ans)
else:
	print(0)


(l1, r1, l2, r2, k) = map(int, input().split())
beg = max(l1, l2)
end = min(r1, r2)
ans = 0
if beg <= end:
	ans += end - beg + 1
if k >= beg and k <= end:
	ans -= 1
print(max(ans, 0))


(l1, r1, l2, r2, k) = [int(i) for i in input().split()]
if l1 > r2:
	ans = 0
elif l2 > r1:
	ans = 0
elif l1 < l2:
	if r1 < r2:
		ans = r1 - l2 + 1
		if k <= r1:
			if k >= l2:
				ans -= 1
	else:
		ans = r2 - l2 + 1
		if k <= r2:
			if k >= l2:
				ans -= 1
elif r1 < r2:
	ans = r1 - l1 + 1
	if k <= r1:
		if k >= l1:
			ans -= 1
else:
	ans = r2 - l1 + 1
	if k <= r2:
		if k >= l1:
			ans -= 1
print(ans)


(a, b, c, d, e) = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
f = max(a, c)
g = min(d, b)
if f > g:
	print(0)
elif f <= e <= g:
	print(g - f)
else:
	print(g - f + 1)