import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		new ABC127().c();
	}
}

class ABC127{
	void c(){
		int N, M;
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		M = in.nextInt();
		int[] s = new int[N+2];
		for(int i=0; i<M; ++i){
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		}
		int ans = 0;
		for(int i=1; i<N+2; ++i){
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		}
		System.out.println(ans);
		in.close();
	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
	public static void main(String[] args) throws IOException {
		new ABC127().c();
	}
} Main public static void main(String[] args) throws IOException {
		new ABC127().c();
	} main {
		new ABC127().c();
	} new ABC127().c() new ABC127().c new ABC127() String[] args args class ABC127{
	void c(){
		int N, M;
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		M = in.nextInt();
		int[] s = new int[N+2];
		for(int i=0; i<M; ++i){
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		}
		int ans = 0;
		for(int i=1; i<N+2; ++i){
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		}
		System.out.println(ans);
		in.close();
	}
} ABC127 void c(){
		int N, M;
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		M = in.nextInt();
		int[] s = new int[N+2];
		for(int i=0; i<M; ++i){
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		}
		int ans = 0;
		for(int i=1; i<N+2; ++i){
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		}
		System.out.println(ans);
		in.close();
	} c {
		int N, M;
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		M = in.nextInt();
		int[] s = new int[N+2];
		for(int i=0; i<M; ++i){
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		}
		int ans = 0;
		for(int i=1; i<N+2; ++i){
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		}
		System.out.println(ans);
		in.close();
	} int N N M; M Scanner in = new Scanner(System.in); in new Scanner(System.in) N = in.nextInt() N in.nextInt() in.nextInt in M = in.nextInt() M in.nextInt() in.nextInt in int[] s = new int[N+2]; s new int[N+2] N+2 N 2 for(int i=0; i<M; ++i){
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		} int i=0; int i=0; i 0 i<M i M ++i ++i i {
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		} {
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		} int L = in.nextInt(); L in.nextInt() in.nextInt in int R = in.nextInt(); R in.nextInt() in.nextInt in s[L]++ s[L] s L s[R+1]-- s[R+1] s R+1 R 1 int ans = 0; ans 0 for(int i=1; i<N+2; ++i){
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		} int i=1; int i=1; i 1 i<N+2 i N+2 N 2 ++i ++i i {
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		} {
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		} s[i] += s[i-1] s[i] s i s[i-1] s i-1 i 1 if(s[i] == M){
				ans++;
			} s[i] == M s[i] s i M {
				ans++;
			} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans in.close() in.close in public class Main {
	public static void main(String[] args) throws IOException {
		new ABC127().c();
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		new ABC127().c();
	}
} Main
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		new ABC127().c();
	}
}

class ABC127{
	void c(){
		int N, M;
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		M = in.nextInt();
		int[] s = new int[N+2];
		for(int i=0; i<M; ++i){
			//[L,R] -> [L, R+1)
			int L = in.nextInt();
			int R = in.nextInt();
			s[L]++;
			s[R+1]--;
		}
		int ans = 0;
		for(int i=1; i<N+2; ++i){
			s[i] += s[i-1];
			if(s[i] == M){
				ans++;
			}
		}
		System.out.println(ans);
		in.close();
	}
}
