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

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)
max_l = 0
min_r = N
for i in range(M):
    if max_l < L[i]:
        max_l = L[i]
    if min_r > R[i]:
        min_r = R[i]
if max_l > min_r:
    print(0)
else:
    print(min_r - max_l + 1) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L = [] L [] R = [] R [] for i in range(M):
    l, r, = map(int, input().split())
    L.append(l)
    R.append(r) i range(M) range M l, r, = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r L.append(l) L.append L append l R.append(r) R.append R append r max_l = 0 max_l 0 min_r = N min_r N for i in range(M):
    if max_l < L[i]:
        max_l = L[i]
    if min_r > R[i]:
        min_r = R[i] i range(M) range M if max_l < L[i]:
        max_l = L[i]
     max_l < L[i] max_l L[i] L i max_l = L[i] max_l L[i] L i if min_r > R[i]:
        min_r = R[i] min_r > R[i] min_r R[i] R i min_r = R[i] min_r R[i] R i if max_l > min_r:
    print(0)
else:
    print(min_r - max_l + 1) max_l > min_r max_l min_r print(0) print 0 print(min_r - max_l + 1) print min_r - max_l + 1 min_r - max_l min_r max_l 1 M = map(int, input().split()) map(int, input().split()) M min_r = N N min_r r, = map(int, input().split()) map(int, input().split()) r max_l = 0 0 max_l L = [] [] L min_r = R[i] R[i] min_r max_l = L[i] L[i] max_l N, M = map(int, input().split()) map(int, input().split()) N R = [] [] R l, r, = map(int, input().split()) map(int, input().split()) l
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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)
max_l = 0
min_r = N
for i in range(M):
    if max_l < L[i]:
        max_l = L[i]
    if min_r > R[i]:
        min_r = R[i]
if max_l > min_r:
    print(0)
else:
    print(min_r - max_l + 1)
