Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. 

The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has n students. Dean's office allows i-th student to use the segment (l_{i}, r_{i}) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students!

Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (n - 1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1.


-----Input-----

The first line contains a positive integer n (1 ≤ n ≤ 100). The (i + 1)-th line contains integers l_{i} and r_{i} (0 ≤ l_{i} < r_{i} ≤ 100) — the endpoints of the corresponding segment for the i-th student.


-----Output-----

On a single line print a single number k, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.


-----Examples-----
Input
3
0 5
2 8
1 6

Output
1

Input
3
0 10
1 5
7 15

Output
3



-----Note-----

Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.

In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1.

In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3.

Source: codeforces | Difficulty: MEDIUM
Tags: Implementation


Solutions:
l = [i for i in range(101)]
(c, x, y) = (0, 0, 0)
for i in range(int(input())):
	(n, m) = map(int, input().split())
	if i == 0:
		(x, y) = (n, m)
	else:
		for j in range(n, m):
			l[j] = -1
for i in range(x, y):
	if l[i] != -1 and l[i + 1] == -1 or (l[i] != -1 and l[i + 1] != -1):
		c += 1
print(c)


def main():
	n = int(input())
	_input = list(map(int, input().split()))
	_start = _input[0]
	_end = _input[1]
	Alexey = []
	for _ in range(_start, _end):
		Alexey.append(0)
	for _ in range(n - 1):
		_input = list(map(int, input().split()))
		start = _input[0]
		end = _input[1]
		for _index in range(start - _start, end - _start):
			if _index >= 0 and _index < len(Alexey):
				Alexey[_index] = 1
	print(Alexey.count(0))
main()


students = int(input())
segment = input().split(' ')
alsegment = list()
for i in range(int(list(segment)[0]), int(list(segment)[1])):
	alsegment.append(i)
for i in range(1, students):
	segment = input().split(' ')
	for i in range(int(list(segment)[0]), int(list(segment)[1])):
		if i in alsegment:
			alsegment.remove(i)
print(len(alsegment))


n = int(input())
l = []
for _ in range(n):
	l.append(list(map(int, input().split())))
arr = [0] * 101
for i in range(1, n):
	arr[l[i][0]] += 1
	arr[l[i][1]] -= 1
for i in range(1, 101):
	arr[i] = arr[i] + arr[i - 1]
cnt = 0
for i in range(l[0][0], l[0][1]):
	if arr[i] == 0:
		cnt += 1
print(cnt)


qq = lambda : map(int, input().split())
a = []
(n,) = qq()
a.append(list(qq()))
for _ in range(n - 1):
	(x, y) = qq()
	for k in range(len(a)):
		for i in a:
			if x <= i[0] and y >= i[1]:
				a.remove(i)
			elif y < i[0] or x > i[1]:
				continue
			elif x <= i[0] and y < i[1]:
				a.append([y, i[1]])
				a.remove(i)
			elif x > i[0] and y >= i[1]:
				a.append([i[0], x])
				a.remove(i)
			elif i[0] < x and y < i[1]:
				a.append([i[0], x])
				a.append([y, i[1]])
				a.remove(i)
s = 0
for i in a:
	s += i[1] - i[0]
print(s)


n = int(input())
(m, M) = list(map(int, input().split()))
x = set(((i, i + 1) for i in range(m, M)))
for _ in range(n - 1):
	(a, b) = list(map(int, input().split()))
	for i in range(a, b):
		if (i, i + 1) in x:
			x.remove((i, i + 1))
print(len(x))


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = []
for i in range(n):
	a.append(tuple(mints()))
r = 0
for i in range(*a[0]):
	r += 1
	for j in range(1, len(a)):
		z = a[j]
		if z[0] <= i and z[1] > i:
			r -= 1
			break
print(r)


from itertools import accumulate
n = int(input())
mas = list([0 for x in range(101)])
(x0, y0) = list(map(int, input().split()))
for i in range(n - 1):
	(x, y) = list(map(int, input().split()))
	mas[x] += 1
	mas[y] -= 1
ans = list(accumulate(mas))[x0:y0].count(0)
print(ans)


g = int(input())
(o, p) = map(int, input().split())
m = set()
for i in range(g - 1):
	(x, y) = map(int, input().split())
	for j in range(x, y):
		m.add(j)
c = 0
for i in range(o, p):
	if i not in m:
		c += 1
print(c)


import time
import io
import math
import random

def timer(f):

	def tmp(*args, **kwargs):
		t = time.time()
		res = f(*args, **kwargs)
		print('Time : %f' % (time.time() - t))
		return res
	return tmp
n = int(input())
array = []
for i in range(n):
	str = input().split(' ')
	array.append([int(str[0]), int(str[1])])
summ = 0
x = array[0][0]
y = array[0][1]
for i in range(x * 100, y * 100):
	coord = i / 100
	f = True
	for j in range(1, len(array)):
		if array[j][0] <= coord <= array[j][1]:
			f = False
	if f:
		summ = summ + 1
print(int(round(summ / 100)))


from sys import setrecursionlimit, exit, stdin
from math import ceil, floor, acos, pi
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from functools import reduce
import itertools
setrecursionlimit(10 ** 7)
RI = lambda x=' ': list(map(int, input().split(x)))
RS = lambda x=' ': input().rstrip().split(x)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
mod = int(1000000000.0 + 7)
eps = 1e-06
MAX = 1000
taken = [0] * 100
n = RI()[0]
(l1, r1) = RI()
for i in range(1, n):
	(l, r) = RI()
	for j in range(l, r):
		taken[j] = 1
ans = 0
for i in range(l1, r1):
	if not taken[i]:
		ans += 1
print(ans)


n = int(input())
(a1, a2) = [float(x) for x in input().split()]
L = set()
Li = set()
i = a1 + 0.5
while i <= a2:
	L.add(i)
	i += 1
for j in range(n - 1):
	(a, b) = [float(x) for x in input().split()]
	L1 = set()
	i = a
	while i <= b:
		L1.add(i)
		i += 0.5
	L = L.difference(L1)
print(len(L))


n = int(input())
dryer = [None] * 100
for i in range(n):
	(a, b) = map(int, input().split())
	for j in range(a, b):
		dryer[j] = i
print(dryer.count(0))


n = int(input())
Al_r = input()
Al = int(Al_r.split(' ')[0])
Ar = int(Al_r.split(' ')[1])
Al_rList = list(range(Al, Ar))
for i in range(n - 1):
	l_r = input()
	l = int(l_r.split(' ')[0])
	r = int(l_r.split(' ')[1])
	l_rList = list(range(l, r))
	for i in l_rList:
		if i in Al_rList:
			Al_rList.remove(i)
print(len(Al_rList))


n = int(input())
s = [0 for q in range(0, 101)]
(la, ra) = [int(q) for q in input().split()]
for i in range(la, ra):
	s[i] = 1
for j in range(n - 1):
	(l, r) = [int(q) for q in input().split()]
	for i in range(l, r):
		s[i] = 0
print(sum(s))


n = int(input())
ar = [0 for i in range(100 + 1)]
(a, b) = map(int, input().split())
for i in range(a, b):
	ar[i] = 1
for i in range(1, n):
	(x, y) = map(int, input().split())
	for j in range(x, y):
		ar[j] = 2
s = 0
flg = 0
for i in range(a, b + 1):
	if ar[i] == 1:
		s += 1
print(s)


n = int(input())
alexy = list(map(int, input().split(' ')))
a = [False for i in range(101)]
for i in range(n - 1):
	x = list(map(int, input().split(' ')))
	for i in range(x[0], x[1]):
		a[i] = True
print(sum((a[i] == False for i in range(alexy[0], alexy[1]))))


n = int(input())
(x, y) = map(int, input().split())
s1 = set(list(range(x, y)))
entire = set(list(range(0, 100)))
for i in range(n - 1):
	(x, y) = map(int, input().split())
	s2 = set(list(range(x, y)))
	s1 = s1.intersection(entire - s2)
print(len(s1))


class CodeforcesTask397ASolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.segments = []

	def read_input(self):
		self.n = int(input())
		for x in range(self.n):
			self.segments.append([int(y) for y in input().split(' ')])

	def process_task(self):
		segment = [1 if self.segments[0][0] <= x < self.segments[0][1] else 0 for x in range(100)]
		for x in range(self.n - 1):
			for y in range(self.segments[x + 1][0], self.segments[x + 1][1]):
				segment[y] = 0
		self.result = str(sum(segment))

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


from operator import itemgetter

def get_length(input, n):
	result = 0
	result_dict = {}
	check = True
	for i in range(0, n):
		for j in range(input[i][0], input[i][1]):
			if check:
				result_dict[j] = True
			else:
				result_dict[j] = False
		check = False
	for (key, value) in result_dict.items():
		if value:
			result += 1
	return result
n = int(input())
input_list = []
for i in range(0, n):
	(x, y) = map(int, input().split())
	input_list.append(list([x, y]))
print(get_length(input_list, n))


n = int(input())
rope = [True] * 100
(x1, y1) = map(int, input().split())
for _ in range(1, n):
	(x, y) = map(int, input().split())
	for i in range(x, y):
		rope[i] = False
total_len = sum(rope[x1:y1])
print(total_len)


n = int(input())
w = [False for i in range(101)]
(a, b) = map(int, input().split())
s = -1
e = -1
cnt = 0
for i in range(n - 1):
	(c, d) = map(int, input().split())
	for j in range(c, d):
		w[j] = True
for i in range(a, b):
	if not w[i]:
		cnt += 1
print(cnt)


bot = True
n = int(input())
d = [1] * 100
(a, b) = list(map(int, input().split()))
for _ in range(n - 1):
	(l, r) = list(map(int, input().split()))
	for i in range(l, r):
		d[i] = 0
print(sum(d[a:b]))


N = int(input())
sush = [0] * 101
for i in range(1, N + 1):
	(l, r) = [int(s) for s in input().split()]
	for j in range(l, r):
		sush[j] = 1 if i == 1 else 0
print(str(sum(sush)))


n = int(input())
(l, r) = map(int, input().split())
lst = [0] * 100
for i in range(n - 1):
	(a1, a2) = map(int, input().split())
	lst[a1:a2] = [1 for i in range(a2 - a1)]
c = 0
for i in range(l, r):
	if lst[i] == 0:
		c += 1
print(c)


n = int(input())
a = [1] * 100
(x, y) = map(int, input().split())
for i in range(n - 1):
	(l, r) = map(int, input().split())
	for j in range(l, r):
		a[j] = 0
print(sum(a[x:y]))


def main():
	from collections import defaultdict
	n = int(input())
	s = defaultdict(int)
	(aa, ab) = map(int, input().split(' '))
	l = []
	for i in range(n - 1):
		(a, b) = map(int, input().split(' '))
		l.append((a, b))
		while a < b:
			s[a] += 1
			a += 1
	r = 0
	while aa < ab:
		if s[aa] == 0:
			r += 1
		aa += 1
	return r
print(main())


n = int(input())
lst = [1] * 100
(a, b) = [int(k) for k in input().split()]
for i in range(n - 1):
	(x, y) = [int(z) for z in input().split()]
	for j in range(x, y):
		lst[j] = 0
print(sum(lst[a:b]))


n = int(input())
a1 = list()
for i in range(0, 101):
	a1.insert(i, 0)
for i in range(0, n):
	(a, b) = map(int, input().split())
	if i != 0:
		for j in range(a, b):
			a1[j] = 1
	else:
		l = a
		r = b
ans = 0
for i in range(l, r):
	if a1[i] == 0:
		ans = ans + 1
print(ans)


n = int(input())
seta = set()
(ax, ay) = map(int, input().split(' '))
for i in range(ax, ay):
	seta.add(i + 0.5)
for i in range(0, n - 1):
	(nx, ny) = map(int, input().split(' '))
	for j in range(nx, ny):
		seta.discard(j + 0.5)
print(len(seta))


n = int(input())
(al, ar) = [int(x) for x in input().split()]
alexSpace = {x: True for x in range(al, ar)}
for i in range(1, n):
	(l, r) = [int(x) for x in input().split()]
	for i1 in range(l, r):
		if i1 in alexSpace.keys():
			alexSpace[i1] = False
print(len({x: isFree for (x, isFree) in alexSpace.items() if isFree}))


from sys import stdin, stdout
n = int(stdin.readline().strip())
alex = list(map(int, stdin.readline().strip().split()))
alex_lst = list(range(alex[0] + 1, alex[1] + 1))
for i in range(1, n):
	lst = list(map(int, stdin.readline().strip().split()))
	for j in range(lst[0] + 1, lst[1] + 1):
		if j in alex_lst:
			alex_lst.remove(j)
stdout.write(str(len(alex_lst)))


n = int(input())
m = []
for _ in range(n):
	(l, r) = map(int, input().split())
	o = [x for x in range(l + 1, r + 1)]
	m.append(o)
c = 0
p = []
for i in range(1, n):
	p += m[i]
p = list(set(p))
for i in m[0]:
	if i not in p:
		c += 1
print(c)


def do():
	n = int(input())
	(x, y) = map(int, input().split(' '))
	d = [1] * (y - x)
	for _ in range(n - 1):
		(a, b) = map(int, input().split(' '))
		for i in range(max(x, a), min(y, b)):
			d[i - x] = 0
	return sum(d) if d else 0
print(do())


n = int(input())
segments = []
for _ in range(n):
	segments.append(list(map(int, input().split())))
l = segments[0][0]
r = segments[0][1]
list_of_tuples = []
for i in range(l, r):
	list_of_tuples.append((i, i + 1))
i = 1
while i < n:
	for j in range(segments[i][0], segments[i][1]):
		if (j, j + 1) in list_of_tuples:
			list_of_tuples.remove((j, j + 1))
	i += 1
print(len(list_of_tuples))


n = int(input())
f = 1
start = []
end = []
main = []
res = []
for i in range(n):
	num = list(map(int, input().split()))
	main.append(num[0])
	main.append(num[1])
	if f == 1:
		f = 0
		als = num[0]
		ale = num[1]
		continue
	start.append(num[0])
	end.append(num[1])
m = max(main)
res = [1] * m
for i in range(als, ale):
	res[i] = 0
for j in range(len(start)):
	for i in range(start[j], end[j]):
		res[i] = 1
print(res.count(0))


n = int(input())
line = input()
line = line.split()
start = int(line[0])
end = int(line[1])
alex = []
for i in range(start, end):
	alex.append(i)
for i in range(0, n - 1):
	line = input()
	line = line.split()
	start = int(line[0])
	end = int(line[1])
	if start <= alex[-1]:
		l = len(alex)
		k = 0
		while k < l:
			if alex[k] >= start and alex[k] < end:
				alex.pop(k)
				l = l - 1
			elif alex[k] >= end:
				break
			else:
				k = k + 1
	if len(alex) == 0:
		break
print(len(alex))


num_of_student = int(input())
sush = list()
for i in range(0, num_of_student):
	inp = input()
	inp_spl = inp.split(' ')
	sush.append(int(inp_spl[0]))
	sush.append(int(inp_spl[1]))
one_range = [0 for i in range(0, max(sush) + 1)]
for i in range(0, num_of_student * 2, 2):
	for j in range(sush[i], sush[i + 1]):
		one_range[j] = i + 1
count = 0
for i in one_range:
	if i == 1:
		count += 1
print(count)


n = int(input())
d = []
count = 0
c = []
for j in range(n):
	(a, b) = map(int, input().split())
	for i in range(a, b):
		if i not in c:
			c.append(i)
		if j != 0:
			d.append(i)
for i in range(min(c), max(c) + 1):
	if i in d:
		if i in c:
			c.remove(i)
print(len(c))


n = int(input())
(x, y) = map(int, input().split())
arr = list()
for i in range(n - 1):
	v = tuple(map(int, input().split()))
	arr.append(v)
ans = 0
for i in range(x, y):
	result = True
	for j in arr:
		if j[0] <= i <= j[1] and j[0] <= i + 1 <= j[1]:
			result = False
	if result:
		ans += 1
print(ans)


from operator import itemgetter

def on_segments_own_points(segment_list) -> int:
	(alexey_l, alexey_r) = segment_list[0]
	if len(segment_list) == 1:
		return alexey_r - alexey_l
	segment_list.sort(key=itemgetter(0))
	(l_curr, r_curr) = segment_list[0]
	i = 0
	while not (l_curr == alexey_l and r_curr == alexey_r):
		i += 1
		(l_curr, r_curr) = segment_list[i]
	if i > 0:
		(l_curr, r_curr) = max(segment_list[:i], key=itemgetter(1))
		if r_curr >= alexey_r:
			return 0
		elif alexey_l <= r_curr < alexey_r:
			start = r_curr
		else:
			start = alexey_l
	else:
		start = alexey_l
	non_overlapped = 0
	for j in range(i + 1, len(segment_list)):
		(l_curr, r_curr) = segment_list[j]
		if start < l_curr:
			if l_curr < alexey_r:
				non_overlapped += l_curr - start
				if r_curr > alexey_r:
					return non_overlapped
				else:
					start = r_curr
			else:
				return alexey_r - start
		elif start > r_curr:
			continue
		elif r_curr < alexey_r:
			start = r_curr
		else:
			return non_overlapped
	if start < alexey_r:
		return non_overlapped + alexey_r - start
	return non_overlapped
n = int(input())
segments = [tuple(map(int, input().split())) for i in range(n)]
print(on_segments_own_points(segments))


import sys

def main():
	n = int(sys.stdin.readline())
	intervals = []
	for _ in range(n):
		(b, e) = [int(x) for x in sys.stdin.readline().split()]
		intervals.append((b, e))
	arr = [0 for _ in range(101)]
	for i in range(intervals[0][0], intervals[0][1]):
		arr[i] = 1
	for interval in intervals[1:]:
		for i in range(interval[0], interval[1]):
			arr[i] = 2
	print(arr.count(1))
main()


import sys
sys.setrecursionlimit(1000000)

def solve():
	(n,) = rv()
	count = [0] * 100
	(leftmost, rightmost) = rv()
	for seg in range(n - 1):
		(left, right) = rv()
		for val in range(left, right):
			count[val] += 1
	res = 0
	for val in range(leftmost, rightmost):
		if count[val] == 0:
			res += 1
	print(res)

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

def rl(n):
	return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


n = int(input())
l1 = list(map(int, input().split()))
x = l1[0]
y = l1[1]
flag = 0
if n == 1:
	flag = 1
q = []
for i in range(x, y + 1):
	q.append(i)
l2 = []
for j in range(0, n - 1):
	temp = list(map(int, input().split()))
	l2.append(temp)
for i in l2:
	if i == l1:
		q = []
		flag = 1
		break
	else:
		for j in range(i[0], i[1]):
			if j == y:
				flag = 1
			if j in q:
				q.remove(j)
hi = len(q)
if flag == 0:
	hi = hi - 1
if n == 1:
	print(hi - 1)
else:
	print(hi)


n = int(input())
d = [1] * 100
(a, b) = map(int, input().split())
for tc in range(n - 1):
	(l, r) = map(int, input().split())
	for i in range(l, r):
		d[i] = 0
print(sum(d[a:b]))


n = int(input())

def nhap():
	temp = input()
	temp = temp.split(' ')
	return [int(temp[0]), int(temp[1])]
(l0, r0) = nhap()
a = dict()
_ = l0 + 0.5
while _ < r0:
	a[_] = 1
	_ += 1
for i in range(n - 1):
	(l, r) = nhap()
	_ = l + 0.5
	while _ < r:
		a[_] = 0
		_ += 1
temp = a.values()
sum = 0
for i in temp:
	sum += i
print(sum)


used = [0] * 100
n = int(input())
(l, r) = map(int, input().split())
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	for i in range(a, b):
		used[i] = 1
print(used[l:r].count(0))


n = int(input())
(Al, Ar) = map(int, input().split())
cnt = [0] * 101
for i in range(n - 1):
	(l, r) = map(int, input().split())
	for j in range(l, r):
		cnt[j] = 1
ans = 0
for i in range(Al, Ar):
	if cnt[i] == 0:
		ans += 1
print(ans)


n = int(input())
sags = list()
i = 1
while i <= n:
	(a, b) = input().split(' ')
	sags.append(list(range(int(a), int(b))))
	i += 1
mysag = sags[0]
i = 0
while i < len(mysag):
	j = 1
	while j < len(sags):
		if mysag[i] in sags[j]:
			mysag[i] = -1
		j += 1
	i += 1
myblock = [x for x in mysag if x != -1]
print(len(myblock))


quantity = [False] * 101
n = int(input())
(l, r) = map(int, input().split())
for i in range(l, r):
	quantity[i] = True
for i in range(n - 1):
	(l, r) = map(int, input().split())
	for j in range(l, r):
		quantity[j] = False
res = 0
for value in quantity:
	if value:
		res += 1
print(res)


import sys
import math

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

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

def read_string():
	return input().strip()

def read_string_list(delim=' '):
	return input().strip().split(delim)
n = read_int()
segments = [0] * 101
(x, y) = read_int_list()
segments[x] += 1
if y < len(segments):
	segments[y] -= 1
for i in range(n - 1):
	(_x, _y) = read_int_list()
	segments[_x] += 1
	if y < len(segments):
		segments[_y] -= 1
for i in range(1, len(segments)):
	segments[i] += segments[i - 1]
counter = 0
for i in range(x, min(y, len(segments))):
	if segments[i] == 1:
		counter += 1
print(counter)


from collections import Counter
from re import findall
n = int(input())
y = [int(i) for i in input().split()]
alex = list(range(y[1]))
for i in range(n - 1):
	(a, b) = [int(x) for x in input().split()]
	for j in range(a, min(b, y[1])):
		alex[j] = 'X'
o = [str(x) for x in alex[y[0]:y[1]]]
o = filter(lambda el: el is not 'X', o)
print(len(list(o)))


estudiantes = int(input())
x = tuple(map(int, input().split()))
Alexey = {i for i in range(x[0], x[1])}
for i in range(estudiantes - 1):
	y = tuple(map(int, input().split()))
	est = {i for i in range(y[0], y[1])}
	Alexey -= est
print(len(Alexey))


n = int(input())
a = [0] * 100
(l, r) = map(int, input().split())
for i in range(n - 1):
	(x, y) = map(int, input().split())
	for i in range(x, y):
		a[i] = 1
ans = 0
for i in range(l, r):
	if not a[i]:
		ans += 1
print(ans)


(n, t) = (int(input()) - 1, [0] * 101)
(a, b) = map(int, input().split())
for i in range(n):
	(l, r) = map(int, input().split())
	t[l] += 1
	t[r] -= 1
for i in range(b - 1):
	t[i + 1] += t[i]
print(t[a:b].count(0))


n = int(input())
(a, b) = map(int, input().split())
l = []
[l.append(i) for i in range(a, b)]
for i in range(n - 1):
	(m, n) = map(int, input().split())
	for j in range(m, n):
		if j in l:
			l.remove(j)
print(len(l))


a = list()
n = int(input())
c = [1] * 100
(l, r) = map(int, input().split())
for i in range(n - 1):
	b = list(map(int, input().split()))
	for j in range(b[0], b[1]):
		c[j] = 0
print(sum(c[l:r]))


n = int(input())
s = [0 for _ in range(100)]
[al, ar] = [int(x) for x in input().split()]
for i in range(al, ar):
	s[i] = 1
for _ in range(1, n):
	[bl, br] = [int(x) for x in input().split()]
	for i in range(bl, br):
		s[i] = 0
print(sum(s))


used = [1] * 100
n = int(input())
me = [int(x) for x in input().split(' ')]
for _ in range(n - 1):
	ot = [int(x) for x in input().split(' ')]
	used[ot[0]:ot[1]] = [0] * (ot[1] - ot[0])
print(sum(used[me[0]:me[1]]))


import sys
n = int(input())
l = []
r = []
for i in range(n):
	(li, ri) = map(int, input().split())
	l.append(li)
	r.append(ri)
a = list(range(l[0], r[0] + 1))
for i in range(1, n):
	if l[i] in a:
		x = []
		x.append('{')
		a = a[:a.index(l[i]) + 1] + x + a[a.index(l[i]) + 1:]
	if r[i] in a:
		x = []
		x.append('}')
		a = a[:a.index(r[i])] + x + a[a.index(r[i]):]
	if l[i] < l[0] and r[i] > r[0]:
		print(0)
		sys.exit()
sum = -1
count = 0
f = 0
for i in range(len(a)):
	if a[i] == '{':
		count += 1
	elif a[i] == '}':
		count -= 1
		f = 1
		if count < 0:
			sum = 0
			count = 0
	elif count == 0:
		sum += 1
		if f == 1:
			f = 0
			sum -= 1
print(sum)


n = int(input())
lrs = []
alr = input().split()
al = int(alr[0])
ar = int(alr[1])
at = ar - al
for i in range(n - 1):
	lr = input().split()
	l = (int(lr[0]), 'l')
	r = (int(lr[1]), 'r')
	lrs.append(l)
	lrs.append(r)
slrs = sorted(lrs, key=lambda x: x[0])
c = 0
lt = 101
for i in range(2 * (n - 1)):
	cur = slrs[i]
	if cur[1] == 'l':
		c += 1
		if c == 1:
			lt = cur[0]
	else:
		c -= 1
		if c == 0:
			if al <= cur[0] and cur[0] <= ar:
				if lt >= al:
					at -= cur[0] - lt
				elif lt < al:
					at -= cur[0] - al
			elif ar < cur[0]:
				if lt <= al:
					at = 0
				elif al < lt and lt < ar:
					at -= ar - lt
			if at <= 0:
				break
			lt = 101
print(at)


l = [1] * 100
n = int(input())
(a, b) = list(map(int, input().split()))
for i in range(n - 1):
	(x, y) = list(map(int, input().split()))
	for i in range(x, y):
		l[i] = 0
print(sum(l[a:b]))


bizy = [0] * 100
n = int(input())
(a_l, a_r) = map(int, input().split())
for i in range(a_l, a_r):
	bizy[i] = 1
for i in range(n - 1):
	(o_l, o_r) = map(int, input().split())
	for i in range(o_l, o_r):
		bizy[i] -= 1
print(bizy[a_l:a_r].count(1))


n = int(input())
l = [0] * 100
for k in range(n):
	(a, b) = map(int, input().split())
	for i in range(a, b):
		l[i] = int(k == 0)
print(sum(l))


def seg_dis(arr, start, end, n):
	for i in range(n):
		for j in range(start[i], end[i]):
			arr[j] = i
	return arr

def fill_arr(arr, n):
	for i in range(n):
		arr.append(0)
	return arr

def count_zeros_range(arr, ini, end):
	cant = 0
	for i in range(ini, end):
		if arr[i] == 0:
			cant = cant + 1
	return cant
n = int(input())
start = [None] * n
end = [None] * n
for i in range(n):
	ele = list(map(int, input().split()))
	start[i] = ele[0]
	end[i] = ele[1]
my_arr = []
fill_arr(my_arr, 100)
my_arr = seg_dis(my_arr, start, end, n)
zeros = count_zeros_range(my_arr, start[0], end[0])
print(zeros)


n = int(input())
li = [0] * 100
for i in range(n):
	if i == 0:
		master = list(map(int, input().rstrip().split()))
	else:
		t = list(map(int, input().rstrip().split()))
		a = t[0]
		b = t[1]
		for x in range(a, b):
			li[x] = 1
ans = 0
for j in range(master[0], master[1]):
	if li[j] == 0:
		ans += 1
print(ans)


def solve(ranges):
	a = set(range(ranges[0][0], ranges[0][1]))
	for (x, y) in ranges[1:]:
		tmp1 = a & set(range(0, x))
		tmp2 = a & set(range(y, 100))
		a = tmp1 | tmp2
	return len(a)

def main():
	n = int(input())
	ranges = list()
	for _ in range(n):
		ranges.append(list(map(int, input().split())))
	print(solve(ranges))
main()


n = int(input())
l = [0 for i in range(100)]
al = [int(i) for i in input().split()]
for i in range(n - 1):
	(l1, r) = input().split()
	(l1, r) = (int(l1), int(r))
	for i in range(l1, r):
		l[i] = 1
l1 = al[0]
r = al[1]
ans = 0
for i in range(l1, r):
	if l[i] == 0:
		ans += 1
print(ans)


n = int(input())
(l1, r1) = map(int, input().split())
S = [0] * 101
for i in range(n - 1):
	(l, r) = map(int, input().split())
	for j in range(l, r):
		S[j] = 1
print(S[l1:r1].count(0))


n = int(input())
segments = [0] * n
for i in range(n):
	segments[i] = tuple(map(int, input().split(' ')))
dry_line = [0] * 101
for s in range(1, n):
	(l, r) = segments[s]
	dry_line[l] -= 1
	dry_line[r] += 1
for i in range(1, 101):
	dry_line[i] += dry_line[i - 1]
print(sum((1 for part in range(segments[0][0], segments[0][1]) if dry_line[part] == 0)))


number_of_segments = int(input())
Alexey_list = list(map(int, input().split(' ')))
start = 0
end = 1
if number_of_segments == 1:
	print(Alexey_list[end] - Alexey_list[start])
	exit(0)

def find_right_inside_or_intersect(left1, right1, left2, right2):
	if left2 > right1:
		return 1
	elif right2 < right1:
		return -1
	else:
		return 0

def insert_into_main_list(main_list, new_range):
	length = len(main_list)
	for i in range(length):
		if new_range[start] < main_list[i][start]:
			main_list.insert(i, new_range)
			return
	main_list.append(new_range)

def update_the_list(main_list):
	length = len(main_list)
	i = 0
	if length == 1:
		return
	while True:
		result = find_right_inside_or_intersect(main_list[i][start], main_list[i][end], main_list[i + 1][start], main_list[i + 1][end])
		if result == -1:
			main_list.pop(i + 1)
			length = length - 1
			i = i - 1
		elif result == 0:
			next_range = main_list.pop(i + 1)
			main_list[i][end] = next_range[end]
			length = length - 1
			i = i - 1
		i = i + 1
		if i == length - 1:
			break

def reduce_the_range(left1, right1, left2, right2):
	if left2 <= left1:
		if right2 <= left1:
			return 0
		if right2 <= right1:
			return right2 - left1
		else:
			return right1 - left1
	if left2 <= right1:
		if right2 <= right1:
			return right2 - left2
		return right1 - left2
	return 0
main_list = []
for i in range(number_of_segments - 1):
	new_range = list(map(int, input().split(' ')))
	insert_into_main_list(main_list, new_range)
update_the_list(main_list)
sum = 0
for i in range(len(main_list)):
	sum = sum + reduce_the_range(Alexey_list[start], Alexey_list[end], main_list[i][start], main_list[i][end])
print(Alexey_list[end] - Alexey_list[start] - sum)


n = int(input())
l = list(map(int, input().split()))
k = set(range(l[0], l[1]))
for i in range(n - 1):
	l = list(map(int, input().split()))
	x = set(range(l[0], l[1]))
	k = k - x
print(len(k))


n = int(input())
al = [int(x) for x in input().split()]
l = []
legend = False
for i in range(n - 1):
	(x, y) = map(int, input().split())
	if x >= al[0] and x <= al[1]:
		if y >= al[1]:
			l.append((x, al[1]))
		else:
			l.append((x, y))
	elif x <= al[0] and y <= al[1] and (y >= al[0]):
		l.append((al[0], y))
	elif x <= al[0] and y >= al[1]:
		legend = True
length = al[1] - al[0]
if len(l) > 0:
	l.sort()
	l1 = [l[0]]
	i = 1
	while i < len(l):
		if l[i][1] <= l1[-1][1]:
			i += 1
		elif l[i][1] >= l1[-1][1] and l[i][0] <= l1[-1][1]:
			l1.append((l1[-1][0], l[i][1]))
			l1.pop(-2)
			i += 1
		else:
			l1.append(l[i])
			i += 1
	for i in range(len(l1)):
		length -= l1[i][1] - l1[i][0]
	print(length)
elif legend:
	print(0)
else:
	print(al[1] - al[0])


import math
import cmath
n = int(input())
m = 0
dd = [0] * 101
(l, r) = map(int, input().split())
for _ in range(l, r):
	dd[_] = 1
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	for x in range(a, b):
		dd[x] = 0
print(sum(dd))


n = int(input())
alex_space = [False] * 100
for i in range(n):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if i == 0:
		alex_space[a:b] = [True] * (b - a)
	else:
		alex_space[a:b] = [False] * (b - a)
print(sum([1 if x else 0 for x in alex_space]))


n = int(input())
lst = [0 for i in range(100)]
(l, r) = map(int, input().split())
for i in range(n - 1):
	(x, y) = map(int, input().split())
	for j in range(x, y):
		lst[j] = 1
ans = 0
for i in range(l, r):
	if lst[i] == 0:
		ans += 1
print(ans)


s = [1 for i in range(100)]
n = int(input())
for i in range(n):
	li = [int(x) for x in input().split()]
	if i == 0:
		(x, y) = (li[0], li[1])
	else:
		(x1, y1) = (li[0], li[1])
		for i in range(x1, y1):
			s[i] = 0
print(s[x:y].count(1))


n = int(input())
dryer = [0] * 101
(al, ar) = map(int, input().split())
for i in range(1, n):
	(l, r) = map(int, input().split())
	for j in range(l, r):
		dryer[j] = 1
x = 0
for i in range(al, ar):
	if dryer[i] == 0:
		x += 1
print(x)


n = int(input())
lefts = []
rights = []
petyaA = []
petyaB = []
(a0, b0) = map(int, input().split())
petyaA.append(a0)
petyaB.append(b0)
length = b0 - a0
for _ in range(1, n):
	(a, b) = map(int, input().split())
	lefts.append(a)
	rights.append(b)
for i in range(n - 1):
	dlina = len(petyaA)
	j = 0
	while j < dlina:
		if lefts[i] > petyaA[j] and rights[i] < petyaB[j]:
			tmp = petyaB[j]
			petyaB[j] = lefts[i]
			petyaA.append(rights[i])
			petyaB.append(tmp)
			length = length - (rights[i] - lefts[i])
		elif lefts[i] > petyaA[j] and rights[i] >= petyaB[j] and (petyaB[j] > lefts[i]):
			length = length - (petyaB[j] - lefts[i])
			petyaB[j] = lefts[i]
		elif lefts[i] <= petyaA[j] and rights[i] >= petyaB[j]:
			length = length - (petyaB[j] - petyaA[j])
			del petyaA[j]
			del petyaB[j]
			dlina = dlina - 1
		elif lefts[i] <= petyaA[j] and rights[i] < petyaB[j] and (petyaA[j] < rights[i]):
			length = length - (rights[i] - petyaA[j])
			petyaA[j] = rights[i]
		elif lefts[i] == petyaA[j] and rights[i] < petyaB[j]:
			petyaA[j] = rights[i]
			length = length - (rights[i] - lefts[i])
		elif lefts[i] > petyaA[j] and rights[i] == petyaB[j]:
			petyaB[j] = lefts[i]
			length = length - (rights[i] - lefts[i])
		j = j + 1
print(length)


n = int(input())
l = [int(i) for i in input().split(' ')]
first = {f for f in range(l[0], l[1])}
for i in range(n - 1):
	l = [int(i) for i in input().split(' ')]
	n = {f for f in range(l[0], l[1])}
	first -= n
print(len(first))


import sys

def find(n, parts):
	safe = set(range(parts[0][0], parts[0][1]))
	for x in parts[1:]:
		safe = safe - set(range(x[0], x[1]))
	return len(safe)
n = input()
parts = []
for i in range(int(n)):
	try:
		(a, b) = input().split()
	except ValueError:
		break
	parts.append([int(a), int(b)])
print(find(n, parts))


n = int(input())
segs = []
total = 0
found = True
for i in range(n):
	segs.append(list(map(int, input().split())))
	segs[i][0] += 0.5
	segs[i][1] -= 0.5
(start, end) = (segs[0][0], segs[0][1])
i = start
while i <= end:
	found = True
	for seg in segs[1:]:
		if i >= seg[0] and i <= seg[1]:
			found = False
			break
	if found:
		total += 1
	i += 1
print(total)


TN = 1

def solution():
	n = int(input())
	(lx, rx) = map(int, input().split())
	anss = [0 for i in range(101)]
	ans = 0
	for i in range(n - 1):
		(l, r) = map(int, input().split())
		for i in range(l, r):
			anss[i] = 1
	for i in range(lx, rx):
		if not anss[i]:
			ans += 1
	print(ans)
while TN != 0:
	solution()
	TN -= 1


n = int(input())
(p, q) = map(int, input().split(' '))
alexey = set(range(p, q))
Union = {}
for i in range(n - 1):
	if i == 0:
		(p, q) = map(int, input().split(' '))
		Union = set(range(p, q))
	else:
		(p, q) = map(int, input().split(' '))
		student = set(range(p, q))
		Union = Union.union(student)
inter = alexey.intersection(Union)
print(len(alexey) - len(inter))


N = int(input())
rope = []
for i in range(100):
	rope.append('n')
(n, m) = input().split()
n = int(n)
m = int(m)
for i in range(n, m):
	rope[i] = 'y'
for i in range(N - 1):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	for i in range(n, m):
		rope[i] = 'n'
print(rope.count('y'))


n = int(input())
(a, b) = [int(i) for i in input().split()]
s1 = set(range(a, b))
for i in range(n - 1):
	(x, y) = [int(i) for i in input().split()]
	s1 -= set(range(x, y))
print(len(s1))


n = int(input())
l = [None] * n
r = [0] * 101
for i in range(n):
	l[i] = list(map(int, input().split()))
for i in range(l[0][0], l[0][1]):
	r[i] = 1
for i in range(1, n):
	il = l[i][0]
	ir = l[i][1]
	for j in range(il, ir):
		r[j] = 0
print(sum(r))


n = int(input())
a = [0] * 100
(la, ra) = map(int, input().split())
for i in range(1, n):
	(l, r) = map(int, input().split())
	a[l] += 1
	if r < 100:
		a[r] -= 1
for i in range(1, 100):
	a[i] += a[i - 1]
ans = 0
for i in range(la, ra):
	if a[i] == 0:
		ans += 1
print(ans)


n = int(input())
(x, y) = map(int, input().split())
r = [False] * 100
r[x:y] = [True] * (y - x)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	r[a:b] = [False] * (b - a)
print(r.count(True))


n = int(input())
coords = []
in1 = input().split()
vasya = []
for i in range(int(in1[0]), int(in1[1])):
	vasya.append(i)
for i in range(n - 1):
	c = input().split()
	for j in range(int(c[0]), int(c[1])):
		if j in vasya:
			vasya.remove(j)
print(len(vasya))


n = int(input())
(a, b) = map(int, input().split())
li = []
for i in range(n - 1):
	(x, y) = map(int, input().split())
	li.append([x, y])
arr = [0] * (100 + 1)
for i in range(n - 1):
	arr[li[i][0]] += 1
	arr[li[i][1]] -= 1
(s, ans) = (0, 0)
for i in range(b + 1):
	if i > a and s == 0:
		ans += 1
	s += arr[i]
print(ans)


n = int(input())
l = []
q = [0] * 100
p = list(map(int, input().split()))
l.append(p)
for i in range(n - 1):
	p = list(map(int, input().split()))
	l.append(p)
	for k in range(p[0], p[1]):
		q[k] = 1
r = 0
for i in range(l[0][0], l[0][1]):
	if q[i] == 0:
		r = r + 1
print(r)


def g(l):
	if len(l) == 1:
		return l
	else:
		ans = [l[0]]
		for i in range(1, len(l)):
			(a, b) = l[i]
			(c, d) = ans[-1]
			if a <= d:
				ans[-1] = (c, max(b, d))
			else:
				ans.append((a, b))
		return ans

def f(l):
	(a, b) = l[0]
	if len(l) == 1:
		return b - a
	else:
		lnew = sorted(l[1:])
		lf = g(lnew)
		ans = b - a
		for i in range(len(lf)):
			(c, d) = lf[i]
			if b <= c:
				break
			elif c < a:
				if d > a:
					if d > b:
						return 0
					else:
						ans = ans - d + a
			elif d > b:
				ans = ans - b + c
			else:
				ans = ans - d + c
		return ans
n = int(input())
l = []
t = 0
while t != n:
	t = t + 1
	x = input().split(' ')
	a = int(x[0])
	b = int(x[1])
	l.append((a, b))
print(f(l))


n = int(input())
h = [1] * 100
(a, b) = map(int, input().split())
for i in range(n - 1):
	(x, y) = map(int, input().split())
	for j in range(x, y):
		h[j] = 0
print(sum(h[a:b]))


n = int(input())
l = []
r = []
for i in range(0, n):
	a = list(map(int, input().split()))
	l.append(a[0])
	r.append(a[1])
ans = 0
for j in range(l[0], r[0]):
	for k in range(1, n):
		if j < r[k] and j >= l[k]:
			break
	else:
		ans += 1
print(str(ans))


n = int(input())
(my_l, my_r) = list(map(int, input().split()))
rope = [0] * 101
for i in range(my_l, my_r):
	rope[i] = 1
for i in range(n - 1):
	(l, r) = list(map(int, input().split()))
	for j in range(l, r):
		rope[j] = 0
print(sum(rope))


n = int(input())
(l, r) = map(int, input().split())
A = []
for i in range(n - 1):
	A += [list(map(int, input().split()))]
A.sort()
ans = 0
for i in A:
	(nl, nr) = (i[0], i[1])
	if l >= nl and r <= nr:
		l = r
		break
	else:
		if nl > l:
			ans += min(r, nl) - l
		l = max(l, nr)
	if l >= r:
		break
if r > l:
	ans += r - l
print(ans)


n = int(input())
(my_low_board, my_high_board) = map(int, input().split())
cut = [0] * 100
for i in range(my_low_board, my_high_board):
	cut[i] = 1
for _ in range(n - 1):
	(low_board, high_board) = map(int, input().split())
	for i in range(low_board, high_board):
		cut[i] = 0
print(sum(cut))


n = int(input())
l = []
h = []
for i in range(n):
	array = input().split()
	array = list(map(lambda x: int(x) if x.isdigit() else 0, array))
	l.append(array[0])
	h.append(array[1])
sum = 0
for i in range(l[0], h[0]):
	ktra = 0
	for j in range(1, len(l)):
		if i >= l[j] and i + 1 <= h[j]:
			ktra = 1
	if ktra == 0:
		sum += 1
print(sum)


n = int(input())
ans = []
dha = [1] * 100
pair = []
for i in range(n):
	(a, b) = map(int, input().split())
	if i == 0:
		temp1 = a
		temp2 = b
	if i != 0:
		pair.append([a, b])
		for j in range(a, b):
			dha[j] = False
ans.sort()
bu = 0
for i in range(temp1, temp2):
	if dha[i] == 1:
		bu += 1
print(bu)


def function(dryer, owner):
	(l, r) = owner
	count = 0
	for i in range(l, r):
		count += not dryer[i]
	return count

def main():
	n = int(input().strip())
	owner = None
	dryer = [0] * 101
	for i in range(n):
		(l, r) = map(int, input().strip().split())
		if owner is None:
			owner = (l, r)
		else:
			for j in range(l, r):
				dryer[j] = 1
	l = function(dryer, owner)
	print(l)
main()


n = int(input())
(a, b) = input().split()
(a, b) = (int(a), int(b))
z = [0] * 101
for i in range(n - 1):
	(S, E) = input().split()
	for i in range(int(S) + 1, int(E) + 1):
		z[i] = 1
print(b - a - z[a + 1:b + 1].count(1))


n = int(input())
(x, y) = input().split()
(x, y) = (int(x), int(y))
l = list(range(x, y))
s = set(l)
for i in range(1, n):
	(p, q) = input().split()
	(p, q) = (int(p), int(q))
	l1 = list(range(p, q))
	s1 = set(l1)
	s = s - s1
print(len(s))


n = int(input())
m = []
(l, r) = (0, 0)
for i in range(n):
	(b1, b2) = list(map(int, input().split(' ')))
	if i == 0:
		(l, r) = (b1, b2)
		m.append((b1, 0))
		m.append((b2, 0))
	else:
		m.append((b1, 1))
		m.append((b2, -1))
m.sort()
(b, a) = (0, [])
cont = False
for i in m:
	b += i[1]
	if not cont and i[1] == 0:
		cont = True
	elif cont and i[1] == 0:
		a.append((i[0], b))
		break
	if cont:
		a.append((i[0], b))
ans = 0
for i in range(len(a[:-1])):
	if a[i][1] == 0:
		ans += a[i + 1][0] - a[i][0]
print(ans)