import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
N=l[0]
M=l[1]
LR=[list(map(int,input().split())) for c in range(M)]
small = 0
large = N
for i in range(M):
    if small<LR[i][0]:
        small=LR[i][0]
    
    if large>LR[i][1]:
        large=LR[i][1]

if  small <= large:
    print(large-small+1)
else:
    print(0) import sys sys import copy copy import math math import itertools itertools import numpy as np numpy int(c) for c in input().split() for c in input().split() c input().split() ().split () input split for c in input().split() int(c) int c l = [int(c) for c in input().split()] l [int(c) for c in input().split()] N=l[0] N l[0] l 0 M=l[1] M l[1] l 1 list(map(int,input().split())) for c in range(M) for c in range(M) c range(M) range M for c 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 c in range(M)] LR [list(map(int,input().split())) for c in range(M)] small = 0 small 0 large = N large N for i in range(M):
    if small<LR[i][0]:
        small=LR[i][0]
    
    if large>LR[i][1]:
        large=LR[i][1] i range(M) range M if small<LR[i][0]:
        small=LR[i][0]
    
     small<LR[i][0] small LR[i][0] [i] LR i 0 small=LR[i][0] small LR[i][0] [i] LR i 0 if large>LR[i][1]:
        large=LR[i][1] large>LR[i][1] large LR[i][1] [i] LR i 1 large=LR[i][1] large LR[i][1] [i] LR i 1 if  small <= large:
    print(large-small+1)
else:
    print(0) small <= large small large print(large-small+1) print large-small+1 large-small large small 1 print(0) print 0 M=l[1] l[1] M l = [int(c) for c in input().split()] [int(c) for c in input().split()] l LR=[list(map(int,input().split())) for c in range(M)] [list(map(int,input().split())) for c in range(M)] LR N=l[0] l[0] N small=LR[i][0] LR[i][0] small large=LR[i][1] LR[i][1] large large = N N large small = 0 0 small
import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
N=l[0]
M=l[1]
LR=[list(map(int,input().split())) for c in range(M)]
small = 0
large = N
for i in range(M):
    if small<LR[i][0]:
        small=LR[i][0]
    
    if large>LR[i][1]:
        large=LR[i][1]

if  small <= large:
    print(large-small+1)
else:
    print(0)