n, m=map(int, input().split())
gate=[]

for i in range(m):
    L, R=map(int, input().split())
    gate.append((L, R))

L_max=0
R_min=10**6
for i in range(m):
    if gate[i][0]>L_max:
        L_max=gate[i][0]

for i in range(m):
    if gate[i][1]<R_min:
        R_min=gate[i][1]


ans=0

for i in range(1, n+1):
    if L_max<=i<=R_min:
        ans+=1

print(ans) n, m=map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m gate=[] gate [] for i in range(m):
    L, R=map(int, input().split())
    gate.append((L, 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 gate.append((L, R)) gate.append gate append (L, R) L R L_max=0 L_max 0 R_min=10**6 R_min 10**6 10 6 for i in range(m):
    if gate[i][0]>L_max:
        L_max=gate[i][0] i range(m) range m if gate[i][0]>L_max:
        L_max=gate[i][0] gate[i][0]>L_max gate[i][0] [i] gate i 0 L_max L_max=gate[i][0] L_max gate[i][0] [i] gate i 0 for i in range(m):
    if gate[i][1]<R_min:
        R_min=gate[i][1] i range(m) range m if gate[i][1]<R_min:
        R_min=gate[i][1] gate[i][1]<R_min gate[i][1] [i] gate i 1 R_min R_min=gate[i][1] R_min gate[i][1] [i] gate i 1 ans=0 ans 0 for i in range(1, n+1):
    if L_max<=i<=R_min:
        ans+=1 i range(1, n+1) range 1 n+1 n 1 if L_max<=i<=R_min:
        ans+=1 L_max<=i<=R_min L_max<=i L_max i R_min ans+=1 ans 1 print(ans) print ans R_min=10**6 10**6 R_min R_min=gate[i][1] gate[i][1] R_min R=map(int, input().split()) map(int, input().split()) R L_max=0 0 L_max ans=0 0 ans L, R=map(int, input().split()) map(int, input().split()) L n, m=map(int, input().split()) map(int, input().split()) n L_max=gate[i][0] gate[i][0] L_max ans+=1 1 ans m=map(int, input().split()) map(int, input().split()) m gate=[] [] gate
n, m=map(int, input().split())
gate=[]

for i in range(m):
    L, R=map(int, input().split())
    gate.append((L, R))

L_max=0
R_min=10**6
for i in range(m):
    if gate[i][0]>L_max:
        L_max=gate[i][0]

for i in range(m):
    if gate[i][1]<R_min:
        R_min=gate[i][1]


ans=0

for i in range(1, n+1):
    if L_max<=i<=R_min:
        ans+=1

print(ans)