import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		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 OK[] = new int[N] ;
//		for( int i = 0 ; i < N ; i ++ ) {
////			OK[i] = 0 ;
//			OK[i] = 1 ;
//		}

		int lmax = 1 ;
		int rmin = N ;
		for( int i = 0 ; i < M ; i ++ ) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				rmin = R[i] ;
			}
		}

//		System.out.println("lmax =" + lmax + ",rmin=" + rmin );
//		for( int i = 0 ; i < M ; i ++ ) {
//			System.out.println("L[i] =" + L[i] + ",R[i]=" + R[i] );
//		}
		if(rmin < lmax ) {
			System.out.println(0);
		}else {
			System.out.println(rmin - lmax + 1);
		}

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		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 OK[] = new int[N] ;
//		for( int i = 0 ; i < N ; i ++ ) {
////			OK[i] = 0 ;
//			OK[i] = 1 ;
//		}

		int lmax = 1 ;
		int rmin = N ;
		for( int i = 0 ; i < M ; i ++ ) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				rmin = R[i] ;
			}
		}

//		System.out.println("lmax =" + lmax + ",rmin=" + rmin );
//		for( int i = 0 ; i < M ; i ++ ) {
//			System.out.println("L[i] =" + L[i] + ",R[i]=" + R[i] );
//		}
		if(rmin < lmax ) {
			System.out.println(0);
		}else {
			System.out.println(rmin - lmax + 1);
		}

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		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 OK[] = new int[N] ;
//		for( int i = 0 ; i < N ; i ++ ) {
////			OK[i] = 0 ;
//			OK[i] = 1 ;
//		}

		int lmax = 1 ;
		int rmin = N ;
		for( int i = 0 ; i < M ; i ++ ) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				rmin = R[i] ;
			}
		}

//		System.out.println("lmax =" + lmax + ",rmin=" + rmin );
//		for( int i = 0 ; i < M ; i ++ ) {
//			System.out.println("L[i] =" + L[i] + ",R[i]=" + R[i] );
//		}
		if(rmin < lmax ) {
			System.out.println(0);
		}else {
			System.out.println(rmin - lmax + 1);
		}

	} main {
		// TODO 自動生成されたメソッド・スタブ
		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 OK[] = new int[N] ;
//		for( int i = 0 ; i < N ; i ++ ) {
////			OK[i] = 0 ;
//			OK[i] = 1 ;
//		}

		int lmax = 1 ;
		int rmin = N ;
		for( int i = 0 ; i < M ; i ++ ) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				rmin = R[i] ;
			}
		}

//		System.out.println("lmax =" + lmax + ",rmin=" + rmin );
//		for( int i = 0 ; i < M ; i ++ ) {
//			System.out.println("L[i] =" + L[i] + ",R[i]=" + R[i] );
//		}
		if(rmin < lmax ) {
			System.out.println(0);
		}else {
			System.out.println(rmin - lmax + 1);
		}

	} 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();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				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();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				rmin = R[i] ;
			}
		} {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				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 if(lmax < L[i] ) {
				lmax = L[i] ;
			} lmax < L[i] lmax L[i] L i {
				lmax = L[i] ;
			} lmax = L[i] lmax L[i] L i if(R[i] < rmin  ) {
				rmin = R[i] ;
			} R[i] < rmin R[i] R i rmin {
				rmin = R[i] ;
			} rmin = R[i] rmin R[i] R i if(rmin < lmax ) {
			System.out.println(0);
		}else {
			System.out.println(rmin - lmax + 1);
		} rmin < lmax rmin lmax {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(rmin - lmax + 1);
		} System.out.println(rmin - lmax + 1) System.out.println System.out System System.out rmin - lmax + 1 rmin - lmax rmin lmax 1 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		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 OK[] = new int[N] ;
//		for( int i = 0 ; i < N ; i ++ ) {
////			OK[i] = 0 ;
//			OK[i] = 1 ;
//		}

		int lmax = 1 ;
		int rmin = N ;
		for( int i = 0 ; i < M ; i ++ ) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				rmin = R[i] ;
			}
		}

//		System.out.println("lmax =" + lmax + ",rmin=" + rmin );
//		for( int i = 0 ; i < M ; i ++ ) {
//			System.out.println("L[i] =" + L[i] + ",R[i]=" + R[i] );
//		}
		if(rmin < lmax ) {
			System.out.println(0);
		}else {
			System.out.println(rmin - lmax + 1);
		}

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		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 OK[] = new int[N] ;
//		for( int i = 0 ; i < N ; i ++ ) {
////			OK[i] = 0 ;
//			OK[i] = 1 ;
//		}

		int lmax = 1 ;
		int rmin = N ;
		for( int i = 0 ; i < M ; i ++ ) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				rmin = R[i] ;
			}
		}

//		System.out.println("lmax =" + lmax + ",rmin=" + rmin );
//		for( int i = 0 ; i < M ; i ++ ) {
//			System.out.println("L[i] =" + L[i] + ",R[i]=" + R[i] );
//		}
		if(rmin < lmax ) {
			System.out.println(0);
		}else {
			System.out.println(rmin - lmax + 1);
		}

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		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 OK[] = new int[N] ;
//		for( int i = 0 ; i < N ; i ++ ) {
////			OK[i] = 0 ;
//			OK[i] = 1 ;
//		}

		int lmax = 1 ;
		int rmin = N ;
		for( int i = 0 ; i < M ; i ++ ) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			if(lmax < L[i] ) {
				lmax = L[i] ;
			}
			if(R[i] < rmin  ) {
				rmin = R[i] ;
			}
		}

//		System.out.println("lmax =" + lmax + ",rmin=" + rmin );
//		for( int i = 0 ; i < M ; i ++ ) {
//			System.out.println("L[i] =" + L[i] + ",R[i]=" + R[i] );
//		}
		if(rmin < lmax ) {
			System.out.println(0);
		}else {
			System.out.println(rmin - lmax + 1);
		}

	}

}
