# -*- coding: utf-8 -*-
"""
Created on Fri Sep 11 01:27:46 2020

@author: liang
"""

N, M = map(int,input().split())
L = list()
R = list()
for i in range(M):
    l, r = map(int,input().split())
    L.append(l)
    R.append(r)

ans = min(R) - max(L) + 1
if ans < 0:
    ans = 0
print(ans) """
Created on Fri Sep 11 01:27:46 2020

@author: liang
""" N, M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L = list() L list() list R = list() R list() list 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 ans = min(R) - max(L) + 1 ans min(R) - max(L) + 1 min(R) - max(L) min(R) min R max(L) max L 1 if ans < 0:
    ans = 0 ans < 0 ans 0 ans = 0 ans 0 print(ans) print ans l, r = map(int,input().split()) map(int,input().split()) l r = map(int,input().split()) map(int,input().split()) r ans = min(R) - max(L) + 1 min(R) - max(L) + 1 ans ans = 0 0 ans M = map(int,input().split()) map(int,input().split()) M L = list() list() L R = list() list() R N, M = map(int,input().split()) map(int,input().split()) N
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 11 01:27:46 2020

@author: liang
"""

N, M = map(int,input().split())
L = list()
R = list()
for i in range(M):
    l, r = map(int,input().split())
    L.append(l)
    R.append(r)

ans = min(R) - max(L) + 1
if ans < 0:
    ans = 0
print(ans)