peterverebics/CodeNet_Python_118 huggingface dataset:
w,h,x,y = map(int,input().split())
 
s = w*h
 
if (w-x)*h > (h-y)*w:
    print((w-x)*h,end = " ")
    print(0)
elif (w-x)*h == (h-y)*w:
    print((w-x)*h,end = " ")
    print(1)
else:
    print((h-y)*w,end = " ")
    print(0)
w, h, x, y = map(int, input().split())

area = w * h / 2

if x == y:
    flg = 1
else:
    flg = 0
    
print(area, flg)
w,h,x,y=map(int,input().split())
print(w*h/2)
if x==w//2 and y==h//2:
  print(1)
else:
  print(0)
w, h ,x, y=map(int, input().split())
m1=min((w-x)*h, x*h)
m2=min((h-y)*w, y*w)

ans=max(m1, m2)

if w-x == x and h-y == y and x == y and w == h:
    p=1
else:
    p=0

print(ans, p)
w,h,x,y = map(int, input().split())
if (x,y) == (w//2, h//2): print(w*h/2, 1)
else: print(w*h/2, 0)
W, H, x, y = map(int, input().split())
print(format(W*H/2, '.9f'), 1 if ((x == W//2) & (y == H//2)) else 0)
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    W, H, x, y = map(int, input().split())
    X, Y = min(x, W-x) * H, min(y, H-y) * W
    print(max(X, Y), int(X == Y))


if __name__ == '__main__':
    main()
w, h, x, y = map(int, input().split())
ans = w * h / 2
r = 0
if x == w // 2 and y == h // 2:
    r += 1
print(ans, r)
w,h,x,y = map(int,input().split())

if w//2==x and h//2==y:
    print((w*h)//2,1)
else:
    print((w*h)//2,0)
W, H, x, y = list(map(int, input().split()))

print(W*H/2, 1 if x == W//2 and y == H//2 else 0)
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

W, H, x, y = rl()

wmin = min((W-x)*H, x*H)
hmin = min(W*(H-y), W*y)
flag = 0
if wmin == hmin:
	flag = 1
print(max(wmin, hmin), flag)
W, H, x, y = map(int, input().split())

"""
直方体は中身を通る線で半分に割ることができる
"""

if W//2 == x and H//2 == y:
    print(W * H / 2, 1)
else:
    print(W * H / 2, 0)
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

W, H, x, y = rl()

wmin = min((W-x)*H, x*H)
hmin = min(W*(H-y), W*y)
flag = 0
if wmin == hmin:
	if wmin != 0:
		flag = 1
print(max(wmin, hmin), flag)
W, H, x, y = map(int, input().split())

# xで分割
left = x * H
right = (W - x) * H
min_x = min(left, right)

# yで分割
down = W * y
up = W * (H - y)
min_y = min(down, up)

print(max(min_x, min_y), int(min_x==min_y))
W, H ,x, y = map(int, input().split())
if H > W:
  if x == W/2:
    can = 0
  else:
    can = 1
elif H == W:
  can = 1
else:
  if y == H/2:
    can = 0
  else:
    can = 1
  
print(float(W*H/2), can)
w,h,x,y = map(int,input().split())
ans = 0
if(x==w//2)and(y==h//2):
  ans = 1
print(w*h/2, ans)
W,H,x,y = map(int,input().split())

a,b = min(x*H, (W-x)*H), min(y*W, (W-y)*W)
if a != b:
    print(max(a,b),0)
else:
    print(a,1)
W , H , x, y = (map(int , input().split()))
men = W * H
bun = x * H
bunbun = y * W
if bun == bunbun:
    ans2 = 1
else:
    ans2 = 0
ans = men - min(bun , bunbun)
print(float(ans) , ans2)
W,H,x,y = map(int,input().split())
ans = float(W*H)/2.0
ans2 = (x==W/2) and (y==H/2)
print(ans,ans2)
w, h , x, y = map(int, input().split())

split_area_smax = (w*h)/2
if  x == w//2 and y ==h//2:
    vari_split = 1
else:
    vari_split = 0


print(split_area_smax, vari_split)
W, H, x, y = map(int, input().split())

#x軸平行
X = min(W*y,W*(H-y))
  #y軸平行
Y = min(x*H, (W-x)*H)
if x*2 == W and y*2 == H:
  print (W*H/2, 1)
elif X == Y:
  print (X, 0)
else:
  print(max(X, Y), 0)
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 11:04:24 2020

@author: liang
"""

W, H, x, y = map(int, input().split())

ans = [0] * 2

ans[0] = H*W/2
if x == W//2 and y == H//2:
    ans[1] = 1
else:
    ans[1] = 0
print(" ".join(map(str, ans)))
I=lambda:list(map(int,input().split()))
w,r,x,y=I()
an=(w-x)*r
ans=(r-y)*w
if an==ans:
  print(an,1)
else:
  print(max(an,ans),0)
w, h, x, y = map(int, input().split())

menseki = 0
bunkatsu = 0

if w / 2 == x and h / 2 == y:
    bunkatsu = 1

if h >= w:
    x0 = x
    y0 = 0
else:
    x0 = 0
    y0 = y

menseki = (w - x0) * (h - y0)
print(menseki, bunkatsu)
def intMap(): return map(int,input().split())

w,h,x,y = intMap()

s = w * h / 2
multi = 0
if x == w // 2 and y == h // 2:
    multi = 1

print("{:.10f} {}".format(s,multi))
w,h,x,y = map(int,input().split())

if w==h:
    print((w*h)//2,1)
else:
    print((w*h)//2,0)
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

w,h,x,y = mi()
ans = w * h / 2
check = 0
if x == w // 2 and y == h // 2:
    check = 1

print('{} {}'.format(ans,check))
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    W, H, x, y = list(map(int, sys.stdin.buffer.readline().split()))
    ret = (W * H) // 2
    p = x == W//2 and y == H//2
    print(ret, 1 if p else 0)


if __name__ == '__main__':
    main()
W,H,x,y = map(int,input().split())

if x*2 == W and y*2 == H:
    print(W*H/2,1)
else:
    a = min(x*H,(W-x)*H)
    b = min(y*W,(H-y)*W)
    print(max(a,b),0)
W, H, x, y = map(int, input().split())

if int(W / 2) == x and int(H // 2) == y:
    a = 1
else:
    a = 0

print(W*H/2, a)
W,H,x,y = map(int,input().split())

a,b = x*H, (W-x)*H
c,d = y*W, (W-y)*W
if min(a,b) == min(c,d):
    print(min(a,b),1)
else:
    print(max(min(a,b),min(c,d)),0)
W,H,X,Y = map(int, input().split())
C = X/W
D = Y/H
if C == 0:
    print(D*W*H)
elif D == 0:
    print(C*W*H)
else:
    print(min(C,D)*W*H)
W,H,x,y=map(int,input().split())
ans1=min(x,W-x)*H
ans2=W*min(y,H-y)
if ans1!=ans2:
	print(max(ans1,ans2),0)
else:
	print(ans1,1)
W, H, x, y = map(int, input().split())

#正方形なら複数　これも面積半分?
#長方形なら一つ 点対称の線を引けば面積半分にできる

if W == H:
    print(W*H/2, 1)
elif W/2 == x and H/2 == y:
    print(W*H/2, 1)
else:
    print(W*H/2, 0)
w,h,x,y=map(int,input().split())
if x==w//2 or y==h//2:
    print(w*h/2,1)
else:
    print(w*h/2,0)
w,h,x,y=map(int,input().split())

if x==w or x==0:
    if y==h or y==0:
        print(0,"0")
else:
    w2=int(w//2)
    h2=int(h//2)

    s1=h*w2
    s2=w*h2
    if s1>s2:
        print(s1,"0")
    elif s1==s2:
        print(s1,"1")
    else:
        print(s2,"0")
w, h, x, y = map(int, input().split())
print(float(w) * float(h) / 2, 1 if x + x == w & y + y == h else 0)
W, H, x, y = map(int, input().split())
print(W * H / 2, 1 if x == W // 2 and y == H // 2 else 0)
w, h, x, y = map(int, input().split())

are_w = min(w*y, w*(h-y))
are_h = min(x*h, (w-x)*h)

ans_are = max(are_w, are_h)
ans = 0
if are_w == are_h:
    ans = 1

if x == w and y == h:
    ans_are = w*h/2
    ans = 0

if x == 0 and y == 0:
    ans_are = w*h/2
    ans = 0

if x == 0 and y == h:
    ans_are = w*h/2
    ans = 0

if x == w and y == 0:
    ans_are = w*h/2
    ans = 0

print(ans_are, ans)
w,h,x,y = map(int,input().split())

if w == x * 2 and h == y * 2:
    print(w*h/2)
    print(1)
else:
    ans = max(h * min(x,w-x), w * min(y,h-y))
    print(ans)
    print(0)
# -*- coding: utf-8 -*-

w, h, x, y = map(int, input().split())

multi = (h/2 == y) or (w/2 == x)

print(w*h/2, 1 if multi else 0)
w,h,x,y = map(int, input().split())

if x == w//2 and y == h//2: print(w*h/2, 1)
else:
    if x >= w/2: a = (w-x) * h
    else: a = x * h
    if y >= h/2: b = (h-y) * w
    else: b = y * w
    print(max(a,b), 0)
w, h, x, y = map(int, input().split())
square = (w * h) / 2
flg = 0
if x == w // 2 and y == h // 2:
    flg = 1
print(square, flg)
W, H, x, y = map(int, input().split(' '))

if x in {0, W} or y in {0, H}:
    print(W * H / 2, 0)
else:
    x1 = x
    x2 = W - x

    y1 = y
    y2 = H - y

    r1 = x1 * H
    r2 = x2 * H
    r3 = y1 * W
    r4 = y2 * W

    r12 = min(r1, r2)
    r34 = min(r3, r4)

    n = 0
    if r12 == r34:
        n = 1

    print(max(r12, r34), n)
def do():
    w,h,x,y=map(int,input().split())
    ar1=(h-y)*w
    ar2=(w-x)*h
    ar=w*h
    if ar1==ar2 and ar/2==ar1:
        return "{} 1".format(ar2)
    elif ar/2==ar1:
        return "{} 0".format(ar1)
    elif ar/2==ar2:
        return "{} 0".format(ar2)
print(do())
w,h,x,y = map(int,input().split())
#必ず半分にできる…とはいえるのか？多分いえる。
#長方形の重心を通るようにひけばok.
ans = w*h/2
if w==h:
	print(ans, 1)
else:
	print(ans, 0)
w, h, x, y = map(int, input().split())
an=[]
if y>=h/2:
  a=w*(h-y)
  an.append(a)
if y<=h/2:
  b=w*y
  an.append(b)
if x>=w/2:
  c=h*(w-x)
  an.append(c)
if x<=w/2:
  d=h*x
  an.append(d)
if y==2*x:
  e=(w*h)/2
  an.append(e)

g = set(an)
l=len(g)
i=len(an)
an.sort()
if l>1:
  T=0
else:
  T=1

print('{} {}'.format(an[-1], T))
w,h,x,y=map(int,input().split())
if w/2==x and h/2==y:k=1
elif w/2==x or h/2==y:k=0
elif w==h:k=0
else:k=1
print(w*h/2,k)
W,H,x,y = map(int,input().split())

ans = max(min(x*H, (W-x)*H), min(y*W, (W-y)*W))
if ans % W and ans % H:
    print(ans,0)
else:
    print(ans,1)
W, H, X, Y = map(int, input().split())

ans1 = (W*H)//2
if X==W//2 and Y==H//2:
    ans2 = 1
else:
    ans2 = 0
print(ans1, ans2)
w,h,x,y=map(int,input().split())

w2=w//2
h2=h//2

if x<=w2:
   w3=w-x
else:
   w3=x
s1=h*w3
    
if y<=h2:
   h3=h-y
else:
   h3=y
s2=w*h2

err1=(s1-s2)/s1

#print("1",w2,h2,s1,s2,err1)

if -1.0*10**(-9)<err1 and err1<1.0*10**(-9):
    print(s1,1)
elif s1>s2:
    print(s1,0)
else:
    print(s2,0)
import sys 

W,H,x,y = map(int, input().split())

area = W*H

patternA = (W-x)*(H)
patternB = (W)*(H-y)

Flag=  0
ans = -10**100


if patternA == patternB:
    Flag = 1
    ans = max(ans, patternA)
    print(str(ans) + " " + str(Flag))

else:
    ans = max(ans, patternA,patternB)
    print(str(ans) + " " + str(Flag))
W,H,x,y = map(int,input().split())
if x == 0 or x == W or y == 0 or y == H:
  half = W * H // 2
  print(half)
  print(0)
  exit()
holizontal = min(W * y,W * (H-y))
vertical = min(H * x,H * (W - x))
print(max(holizontal,vertical))
print(0)
exit()
W,H,x,y=map(int,input().split())
if x==W//2 and y==H//2:
  print(W*H//2,1)
elif x==W//2 and y!=H//2:
  print(W*H//2,0)
elif x!=W//2 and y==H//2:
  print(W*H//2,0)
else:
  print(W*H//2,1)
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, m = Input()
    max_l = 0
    min_r = 1e6
    for i in range(m):
        l, r = Input()
        max_l = max(max_l, l)
        min_r = min(min_r, r)

    ans = min_r - max_l + 1
    ans = max(ans, 0)
    print(ans)

main()
def main():
    n,m=map(int,input().split())
    CARD=[0]*(n+1)
    for i in range(m):
        L,R=map(int,input().split())
        CARD[L-1]+=1
        CARD[R]-=1
    ans=0
    for i in range(n):
        if CARD[i]==m:ans+=1
        CARD[i+1]=CARD[i+1]+CARD[i]

    print(ans)

if __name__=='__main__':
    main()
N, M = map(int, input().split())
lr = [tuple(map(int, input().split())) for _ in range(M)]

s = [0] * (N + 1)
for i in range(M):
    l, r = lr[i]
    s[l - 1] += 1
    if r != N + 2:
        s[r] -= 1

ruiseki = [0] * (N + 2)
for i in range(N + 1):
    ruiseki[i + 1] += ruiseki[i] + s[i]

#max_ = max(ruiseki)
print(ruiseki.count(M))
n,m = map(int,input().split())
l,r = [],[]
for i in range(m):
    a,b = map(int,input().split())
    l.append(a)
    r.append(b)
num = list(range(1,n+1))
lmax = max(l)
rmin = min(r)
if lmax > rmin:
    print(0)
else:
    gate = set(range(lmax,rmin+1))
    ans = list(set(num) & gate)
    print(len(ans))
N, M = map(int, input().split())
max_L = 0
min_R = 10**5
for _ in range(M):
  L, R = map(int, input().split())
  max_L = max(max_L, L)
  min_R = min(min_R, R)
print(len(list(range(max_L, min_R+1))))
N, M = map(int, input().split())

c_min = 1
c_max = 10 ** 5
for i in range(M):
    LM = list(map(int, input().split()))
    c_min = max(c_min, LM[0])
    c_max = min(c_max, LM[1])

if c_min > c_max:
    print(0)
else:
    print(c_max - c_min + 1)
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]

l = []
r = []

for i in range(m):
  l.append(a[i][0])
  r.append(a[i][1])

ans = min(r)-max(l)+1  
 
if ans <= 0:
  print(0)
else:
  print(ans)
n,m = map(int,input().split())
min = 1
max = n

for i in range(m):
    l,r = map(int,input().split()) 
    if min<l: min=l
    if max>r: max=r 

if min>max:
    print(0)
else:
    print(max-min+1)
def resolve():
    N, M = map(int, input().split())

    start_index = 1
    last_index = N
    for _ in range(M):
        pp, ss = map(int, input().split())
        start_index = max(start_index, pp)
        last_index = min(last_index, ss)

    print(max(0, last_index - start_index + 1))


resolve()
N, Q = map(int,input().split())
m = 1
M = N
for k in range(Q):
    L, R = map(int,input().split())
    m = max(L,m)
    M = min(M,R)
print(max(0,M-m+1))
N, M = map(int, input().split())

left = 1
right = N

for _ in range(M):
    l, r = map(int, input().split())

    if left < l:
        left = l
    if right > r:
        right = r

ans = right - left

print(ans + 1 if ans >= 0 else 0)
n, m = map(int, input().split())
low = 0
high = 100001

for i in range(m):
  l,m = map(int, input().split())
  low = max(low, l)
  high = min(high, m)
if high-low+1<0:
  print(0)
else:
  print(min(high-low+1, n))
n, m = map(int, input().split())
l = []
r = []
for i in range(m):
    L, R = map(int, input().split())
    l += [L]
    r += [R]

l_max = max(l)
r_min = min(r)

print(max(r_min - l_max + 1, 0))
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

L_max = 0
R_min = N
for L, R in LR:
    L_max = max(L_max, L)
    R_min = min(R_min, R)

ans = 0
if L_max <= R_min:
    ans = R_min - L_max + 1

print(ans)
N,M=map(int,input().split())
L=[]
R=[]
for i in range(M):
  l,r=[int(i) for i in input().split()]
  L.append(l)
  R.append(r)
Lmax=max(L)
Rmin=min(R)
if Rmin-Lmax>=0:
  print(Rmin-Lmax+1)
else:
  print(0)
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,M = MI()
A = [0]*(N+2)

for i in range(M):
    l,r = MI()
    A[l] += 1
    A[r+1] -= 1

from itertools import accumulate

A = list(accumulate(A))
print(sum(A[i] == M for i in range(1,N+1)))
N, M = map(int, input().split())
gate = [input().split() for i in range(M)]

MIN = 0
MAX = float('inf')

for i in range(M):
    MIN = max(MIN, int(gate[i][0]))
    MAX = min(MAX, int(gate[i][1]))

print(max(MAX - MIN + 1, 0))
N,M = map(int, input().split())
l=0
r=N
for _ in range(M):
  ll,rr=map(int,input().split())
  l = max(l,ll)
  r = min(r,rr)
ans = r - l + 1
print(ans if ans > 0 else 0)
n,m = map(int, input().split())
ns = set(i+1 for i in range(n))
l_min = 0
r_max = n
for i in range(m):
    l, r = map(int, input().split())
    l_min = max(l_min, l)
    r_max = min(r_max, r)
print(max(r_max - l_min+1, 0))
N,M = map(int, input().split())

lm,rm = 0,N
for i in range(0,M):
    l,r = map(int,input().split())
    lm = max(lm,l)
    rm = min(rm,r)
print(rm - lm + 1 if rm >= lm else 0)
N,M = map(int,input().split())

bottom = 0
top = N+1

for i in range(M):
  L,R = map(int,input().split())
  bottom = max(bottom, L)
  top = min(top,R)
  
ans = top - bottom + 1
print(ans if ans>=0 else 0)
n,m = map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(m)]
for i in range(m-1):
  if lr[i][0] > lr[i+1][0]:
    lr[i+1][0] = lr[i][0]
  if lr[i][1] < lr[i+1][1]:
    lr[i+1][1] = lr[i][1]
ans = lr[-1][1] - lr[-1][0] + 1
if ans >= 0:
  print(ans)
else:
  print(0)
N, M = input().split(' ')
N = int(N)
M = int(M)
min = 1
max = N
for i in range(M):
  l, m = input().split(' ')
  l = int(l)
  m = int(m)
  if min>m or max<l:
    print(0)
    break 
  if min < l:
    min = l
  if max > m:
    max = m
else:
  print(max-min+1)
n,m=map(int,input().split())

s=[0]*n
left=[]
right=[]
for i in range(m):
    l,r=map(int,input().split())
    left.append(l)
    right.append(r)
    
if min(right)<max(left):
    print(0)
else:
    print(min(right)-max(left)+1)
N, M = map(int, input().split())
s = -1
t = N+1
for i in range(M):
    l,r =map(int, input().split())
    s = max(s, l)
    t = min(t, r)
    
print(max(0, t-s+1))
N, M = map(int, input().split())

l_max = 1
r_min = N
for _ in range(M):
    l, r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r)

if r_min < l_max:
    print(0)
else:
    print(r_min-l_max+1)
n, m = map(int, input().split())

l_max = 0
r_min = 10**9

for i in range(m):
    l, r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r)

ans = 0
for i in range(l_max, r_min+1):
    ans += 1

print(ans)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

import numpy as np

N,M = map(int,readline().split())
LR = np.array(read().split(),np.int32)

L = LR[::2]; R = LR[1::2]

x = R.min() - L.max() + 1
if x < 0: x = 0
print(x)
n,m = map(int,input().split())
lm,rm = map(int,input().split())
for i in range(m-1):
    l,r = map(int,input().split())
    lm = max(lm,l)
    rm = min(rm,r)
print(max(rm-lm+1,0))
n,m=map(int,input().split())
memo=[0]*n
from itertools import accumulate
for i in range(m):
    l,r=map(lambda x:int(x)-1,input().split())
    memo[l]+=1
    if r+1!=n:
        memo[r+1]-=1
ac=list(accumulate(memo))
print(ac.count(m))
def two_input():
    return map(int, input().split())

N, M = two_input()
L, R = [], []
for i in range(M):
    l, r = two_input()
    L.append(l)
    R.append(r)
    
maxl = max(L)
minr = min(R)

ans = 0
for i in range(N):
    if maxl <= i+1 <= minr:
        ans += 1

print(ans)
n, m = map(int, input().split())
max_l = 1
min_r = n 

for _ in range(m):
    l, r = map(int, input().split())
    max_l = max(max_l, l)
    min_r = min(min_r, r)

ans = max(min_r - max_l + 1, 0)
print(ans)
n,m = map(int, input().split())
l,r = 0,n
for i in range(m):
    L,R = map(int, input().split())
    l = max(l,L)
    r = min(r,R)

print(r-l+1 if l<=r else 0)
n,m=map(int,input().split())

limax=0
rimin=n
for i in range(m):
    li,ri=map(int,input().split())
    if li>limax:
        limax=li
    if ri<rimin:
        rimin=ri
if rimin<limax:
    print(0)
else:
    print(rimin-limax+1)
def solve(lx, rx):
    diff = min(rx) - max(lx)
    ans = diff+1 if diff >= 0 else 0
    return ans


if __name__ == '__main__':
    n, m = map(int, input().split())
    lx = []
    rx = []

    for i in range(m):
        l, r = map(int, input().split())
        lx.append(l)
        rx.append(r)

    print(solve(lx, rx))
S = input()
N = int(S.split(" ")[0])
M = int(S.split(" ")[1])


lArr = []
rArr = []
for i in range(M):
    S = input()
    l1 = int(S.split(" ")[0])
    r1 = int(S.split(" ")[1])
    lArr.append(l1)
    rArr.append(r1)

lArr.sort()
rArr.sort()

l1 = max(lArr)
r1 = min(rArr)

if r1 < l1:
    print(0)
else:
    print(r1 - l1 + 1)
n,a = map(int,input().split())
m = [tuple(map(int,input().split())) for _ in range(a)]

l,r=m[0][0],m[0][1]

for i in range(1,a):
    l = max(m[i][0],l)
    r = min(m[i][1],r)

print(max(r-l+1,0))
n,m=map(int, input().split())
l_ans=1
r_ans=n
for i in range(m):
    l,r=map(int, input().split())
    l_ans=max(l_ans,l)
    r_ans=min(r_ans,r)

if r_ans>=l_ans:
    print(r_ans-l_ans+1)
else:
    print(0)
N, M = map(int, input().split())
mini = 0
maxi = N
for i in range(M):
  L, R = map(int, input().split())
  mini = max(mini, L)
  maxi = min(maxi, R)
print(maxi - mini + 1 if maxi - mini + 1 > 0 else 0)
N, M = map(int, input().split())
a = []
for i in range(M):
    a.append(list(map(int, input().split())))
b = [0, float("INF")]
for i in range(M):
    b[0] = max(a[i][0], b[0])
    b[1] = min(a[i][1], b[1])
if b[0] <= b[1]:
    print(b[1] - b[0] + 1)
else:
    print(0)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
lr = [list(map(int, readline().split())) for _ in range(m)]

left = 0
right = n
for i in range(m):
    left = max(left, lr[i][0])
    right = min(right,lr[i][1])
print(max(0,right-left+1))
n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (min(r) - max(l)   +1) 
if answer > 0:
    print(answer)
else:
    print("0")
n, m = map(int, input().split())

maxl = 0
minr = 10**5
for i in range(m):
  l, r = map(int, input().split())
  maxl = max(maxl, l)
  minr = min(minr, r)

print(max(minr-maxl+1, 0))
N, M = map(int, input().split())
keys = [list(map(int, input().split())) for _ in range(M)]

left = 1
right = N
for key in keys:
    if left < key[0]:
        left = key[0]
    if key[1] < right:
        right = key[1]
if right < left:
    print(0)
else:
    print(right - left + 1)
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

card_min = 0
card_max = N
ans = N
#print(card_min, card_max)
for l, r in LR:
    if l > card_min:
        card_min = l
    if r < card_max:
        card_max = r
    #print(card_min, card_max)
    ans = card_max - card_min + 1
    if ans <= 0:
        ans = 0
        break
print(ans)
n,m=map(int,input().split())
s=0
t=10**10
for i in range(m):
  l,r=map(int,input().split())
  s=max(s,l)
  t=min(t,r)

if s>t:
  print(0)
else:
  print(t-s+1)
N, M = map(int, input().split())

L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

ans = 0
l = max(L)
r = min(R)
for i in range(N):
    if i+1 >= l and i+1 <= r:
        ans += 1

print(ans)
N, M = map(int, input().split())
res = 0
L_max = 0
R_min = 100000
for _ in range(M):
  L, R = map(int, input().split())
  if L_max < L: L_max = L
  if R < R_min: R_min = R
  
  
print(max(0, (R_min - L_max + 1)))
n, m = map(int, input().split())
a = [0]*(n+1)

for i in range(m):
        l, r = map(int, input().split())
        a[l-1] += 1
        a[r] -= 1
for i in range(n): a[i+1] += a[i]

print(a.count(m))
n, m = map(int,input().split())
lst = []
for i in range(m):
    lst.append(list(map(int,input().split())))

min = lst[0][0]
max = lst[0][1]
for v in lst:
    if v[0] > min:
        min = v[0]
    if v[1] < max:
        max = v[1]
if min <= max:
    print(max-min + 1)
elif min > max:
    print(0)
L = []
R = []
N, M = map(int, input().split())
for _ in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0)
n, m = map(int, input().split())
l = 0
r = n
for i in range(m):
    lt, rt = map(int, input().split())
    l = max(l, lt)
    r = min(r, rt)
if(l<=r):
    print(r - l + 1)
else:
    print(0)
data=input().split()
N=int(data[0])
M=int(data[1])
data_gate=[input().split() for i in range(M)]
data_min=[]
data_max=[]
for i in range(M):
    data_min.append(int(data_gate[i][0]))
    data_max.append(int(data_gate[i][1]))
m=max(data_min)
M=min(data_max)
if M>=m:
    ans=M-m+1
else:
    ans=0
print(ans)
n, m = map(int, input().split())
l_lst = []
r_lst = []
for i in range(m):
    l, r = map(int, input().split())
    l_lst.append(l)
    r_lst.append(r)
print(max(0, min(r_lst) - max(l_lst) + 1))
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

lList = [arr[0] for arr in LR]
rList = [arr[1] for arr in LR]

l = max(lList)
r = min(rList)

print(max(r-l+1, 0))
n,m=map(int,input().split())
L=[]
R=[]
for i in range(m):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r)
a=max(L)
b=min(R)
li=[i for i in range(a,b+1)]
print(len(li))
n, m, *lr = list(map(int, open(0).read().split()))
print(max(0, min(lr[1::2]) - max(lr[::2]) + 1))
N,M = list(map(int,input().split()))
MAX = float('-inf')
MIN = float('inf')
for i in range(M):
    L,R = list(map(int,input().split()))
    MAX = max(MAX, L)
    MIN = min(MIN, R)
count = MIN - MAX + 1
if count > 0:
    print(count)
else:
    print(0)