import sys
N, M = map(int, input().split())
ansl = 1
ansr = N
for _ in range(M):
    l, r = map(int, sys.stdin.readline().split())
    ansl = max(ansl, l)
    ansr = min(ansr, r)
ans = max(0, ansr - ansl + 1)
print(ans) import sys sys N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M ansl = 1 ansl 1 ansr = N ansr N for _ in range(M):
    l, r = map(int, sys.stdin.readline().split())
    ansl = max(ansl, l)
    ansr = min(ansr, r) _ range(M) range M l, r = map(int, sys.stdin.readline().split()) l map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split r ansl = max(ansl, l) ansl max(ansl, l) max ansl l ansr = min(ansr, r) ansr min(ansr, r) min ansr r ans = max(0, ansr - ansl + 1) ans max(0, ansr - ansl + 1) max 0 ansr - ansl + 1 ansr - ansl ansr ansl 1 print(ans) print ans r = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) r ansl = 1 1 ansl ansr = N N ansr N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M ansl = max(ansl, l) max(ansl, l) ansl ansr = min(ansr, r) min(ansr, r) ansr l, r = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) l ans = max(0, ansr - ansl + 1) max(0, ansr - ansl + 1) ans
import sys
N, M = map(int, input().split())
ansl = 1
ansr = N
for _ in range(M):
    l, r = map(int, sys.stdin.readline().split())
    ansl = max(ansl, l)
    ansr = min(ansr, r)
ans = max(0, ansr - ansl + 1)
print(ans)