
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 = 1;
		int R = N;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		}
		if(L <= R) {
			ans = R - L + 1;
		}
		System.out.println(ans);
	}

} 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 = 1;
		int R = N;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		}
		if(L <= R) {
			ans = R - L + 1;
		}
		System.out.println(ans);
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int L = 1;
		int R = N;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		}
		if(L <= R) {
			ans = R - L + 1;
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int L = 1;
		int R = N;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		}
		if(L <= R) {
			ans = R - L + 1;
		}
		System.out.println(ans);
	} 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 = 1; L 1 int R = N; R N int ans = 0; ans 0 for(int i = 0; i < M; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		} {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		} int Li = sc.nextInt(); Li sc.nextInt() sc.nextInt sc int Ri = sc.nextInt(); Ri sc.nextInt() sc.nextInt sc L = Math.max(L, Li) L Math.max(L, Li) Math.max Math L Li R = Math.min(R, Ri) R Math.min(R, Ri) Math.min Math R Ri if(L <= R) {
			ans = R - L + 1;
		} L <= R L R {
			ans = R - L + 1;
		} ans = R - L + 1 ans R - L + 1 R - L R L 1 System.out.println(ans) System.out.println System.out System System.out ans 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 = 1;
		int R = N;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		}
		if(L <= R) {
			ans = R - L + 1;
		}
		System.out.println(ans);
	}

} 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 = 1;
		int R = N;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		}
		if(L <= R) {
			ans = R - L + 1;
		}
		System.out.println(ans);
	}

} 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 = 1;
		int R = N;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();
			L = Math.max(L, Li);
			R = Math.min(R, Ri);
		}
		if(L <= R) {
			ans = R - L + 1;
		}
		System.out.println(ans);
	}

}
