N, M = map(int, input().split())

P = [0]*(N+1)

for i in range (0, M):
	A, B = map(int, input().split())
	P[A-1]+=1
	P[B]-=1
    
for i in range (1, N+1):
	P[i]+=P[i-1]
    
P = sorted(P, reverse = True)

count = 0

for i in range (0, N+1):
	if P[i] == M:
		count+=1
	else:
		print(count)
		exit() N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M P = [0]*(N+1) P [0]*(N+1) [0] 0 N+1 N 1 for i in range (0, M):
	A, B = map(int, input().split())
	P[A-1]+=1
	P[B]-=1
     i range (0, M) range 0 M A, B = map(int, input().split()) A map(int, input().split()) map int input().split() ().split () input split B P[A-1]+=1 P[A-1] P A-1 A 1 1 P[B]-=1 P[B] P B 1 for i in range (1, N+1):
	P[i]+=P[i-1]
     i range (1, N+1) range 1 N+1 N 1 P[i]+=P[i-1] P[i] P i P[i-1] P i-1 i 1 P = sorted(P, reverse = True) P sorted(P, reverse = True) sorted P reverse = True reverse True count = 0 count 0 for i in range (0, N+1):
	if P[i] == M:
		count+=1
	else:
		print(count)
		exit() i range (0, N+1) range 0 N+1 N 1 if P[i] == M:
		count+=1
	else:
		print(count)
		exit() P[i] == M P[i] P i M count+=1 count 1 print(count) print count exit() exit N, M = map(int, input().split()) map(int, input().split()) N count+=1 1 count P = [0]*(N+1) [0]*(N+1) P A, B = map(int, input().split()) map(int, input().split()) A B = map(int, input().split()) map(int, input().split()) B P = sorted(P, reverse = True) sorted(P, reverse = True) P M = map(int, input().split()) map(int, input().split()) M count = 0 0 count
N, M = map(int, input().split())

P = [0]*(N+1)

for i in range (0, M):
	A, B = map(int, input().split())
	P[A-1]+=1
	P[B]-=1
    
for i in range (1, N+1):
	P[i]+=P[i-1]
    
P = sorted(P, reverse = True)

count = 0

for i in range (0, N+1):
	if P[i] == M:
		count+=1
	else:
		print(count)
		exit()