import numpy as np

i = list(map(int, input().split()))
N = i[0]
M = i[1]

l = np.array([list(map(int, input().split())) for i in range(M)])

limit1 = max(l[:, 0])
limit2 = min(l[:, 1])

print(max(limit2 - limit1 + 1, 0)) import numpy as np numpy i = list(map(int, input().split())) i list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split N = i[0] N i[0] i 0 M = i[1] M i[1] i 1 list(map(int, input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split l = np.array([list(map(int, input().split())) for i in range(M)]) l np.array([list(map(int, input().split())) for i in range(M)]) np.array np array [list(map(int, input().split())) for i in range(M)] limit1 = max(l[:, 0]) limit1 max(l[:, 0]) max l[:, 0] l : limit2 = min(l[:, 1]) limit2 min(l[:, 1]) min l[:, 1] l : print(max(limit2 - limit1 + 1, 0)) print max(limit2 - limit1 + 1, 0) max limit2 - limit1 + 1 limit2 - limit1 limit2 limit1 1 0 N = i[0] i[0] N limit1 = max(l[:, 0]) max(l[:, 0]) limit1 limit2 = min(l[:, 1]) min(l[:, 1]) limit2 i = list(map(int, input().split())) list(map(int, input().split())) i M = i[1] i[1] M l = np.array([list(map(int, input().split())) for i in range(M)]) np.array([list(map(int, input().split())) for i in range(M)]) l
import numpy as np

i = list(map(int, input().split()))
N = i[0]
M = i[1]

l = np.array([list(map(int, input().split())) for i in range(M)])

limit1 = max(l[:, 0])
limit2 = min(l[:, 1])

print(max(limit2 - limit1 + 1, 0))