import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		int Lmax = 1;
		int Rmin = N;
		for(int i=0;i<M;i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		}
		
		int count = 0;
		for(int i=1;i<=N;i++) {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();		
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		int Lmax = 1;
		int Rmin = N;
		for(int i=0;i<M;i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		}
		
		int count = 0;
		for(int i=1;i<=N;i++) {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();		
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		int Lmax = 1;
		int Rmin = N;
		for(int i=0;i<M;i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		}
		
		int count = 0;
		for(int i=1;i<=N;i++) {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();		
	} main {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		int Lmax = 1;
		int Rmin = N;
		for(int i=0;i<M;i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		}
		
		int count = 0;
		for(int i=1;i<=N;i++) {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M int Lmax = 1; Lmax 1 int Rmin = N; Rmin N for(int i=0;i<M;i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		} {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		} L[i] = sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc Lmax = Math.max(Lmax,L[i]) Lmax Math.max(Lmax,L[i]) Math.max Math Lmax L[i] L i Rmin = Math.min(Rmin, R[i]) Rmin Math.min(Rmin, R[i]) Math.min Math Rmin R[i] R i int count = 0; count 0 for(int i=1;i<=N;i++) {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		} int i=1; int i=1; i 1 i<=N i N i++ i++ i {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		} {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		} if(i>=Lmax && i<=Rmin) {
				count++;
			} i>=Lmax && i<=Rmin i>=Lmax i Lmax i<=Rmin i Rmin {
				count++;
			} count++ count System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		int Lmax = 1;
		int Rmin = N;
		for(int i=0;i<M;i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		}
		
		int count = 0;
		for(int i=1;i<=N;i++) {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();		
	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		int Lmax = 1;
		int Rmin = N;
		for(int i=0;i<M;i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		}
		
		int count = 0;
		for(int i=1;i<=N;i++) {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();		
	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] L = new int[M];
		int[] R = new int[M];
		int Lmax = 1;
		int Rmin = N;
		for(int i=0;i<M;i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			Lmax = Math.max(Lmax,L[i]);
			Rmin = Math.min(Rmin, R[i]);
		}
		
		int count = 0;
		for(int i=1;i<=N;i++) {
			if(i>=Lmax && i<=Rmin) {
				count++;
			}
		}
		
		System.out.println(count);
		sc.close();		
	}

}