import sys

input = sys.stdin.readline
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
common_l, common_r = 0, N
for l, r in LR:
    common_l = max(l, common_l)
    common_r = min(r, common_r)
print(max(0, common_r-common_l+1)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split LR = [list(map(int, input().split())) for _ in range(M)] LR [list(map(int, input().split())) for _ in range(M)] common_l, common_r = 0, N common_l 0 common_r N for l, r in LR:
    common_l = max(l, common_l)
    common_r = min(r, common_r) l r LR common_l = max(l, common_l) common_l max(l, common_l) max l common_l common_r = min(r, common_r) common_r min(r, common_r) min r common_r print(max(0, common_r-common_l+1)) print max(0, common_r-common_l+1) max 0 common_r-common_l+1 common_r-common_l common_r common_l 1 LR = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] LR N, M = map(int, input().split()) map(int, input().split()) N common_l = max(l, common_l) max(l, common_l) common_l common_r = min(r, common_r) min(r, common_r) common_r input = sys.stdin.readline sys.stdin.readline input common_l, common_r = 0, N 0 common_l common_r = 0, N N common_r M = map(int, input().split()) map(int, input().split()) M
import sys

input = sys.stdin.readline
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
common_l, common_r = 0, N
for l, r in LR:
    common_l = max(l, common_l)
    common_r = min(r, common_r)
print(max(0, common_r-common_l+1))
