import java.util.Arrays;
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[] table = new int[100100];
		Arrays.fill(table, 0);
		for (int i = 0; i < M; i++) {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		}


		for (int i = 1; i < table.length; i++) {
			table[i] += table[i - 1];
		}

		/*
		for (int i = 0; i < 10; i++) {
			System.out.println(table[i]);
		}
		*/

		int cnt = 0;
		for (int i = 0; i < table.length; i++) {
			if (table[i] == M) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}
} import java.util.Arrays; Arrays java.util 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[] table = new int[100100];
		Arrays.fill(table, 0);
		for (int i = 0; i < M; i++) {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		}


		for (int i = 1; i < table.length; i++) {
			table[i] += table[i - 1];
		}

		/*
		for (int i = 0; i < 10; i++) {
			System.out.println(table[i]);
		}
		*/

		int cnt = 0;
		for (int i = 0; i < table.length; i++) {
			if (table[i] == M) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] table = new int[100100];
		Arrays.fill(table, 0);
		for (int i = 0; i < M; i++) {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		}


		for (int i = 1; i < table.length; i++) {
			table[i] += table[i - 1];
		}

		/*
		for (int i = 0; i < 10; i++) {
			System.out.println(table[i]);
		}
		*/

		int cnt = 0;
		for (int i = 0; i < table.length; i++) {
			if (table[i] == M) {
				cnt++;
			}
		}

		System.out.println(cnt);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] table = new int[100100];
		Arrays.fill(table, 0);
		for (int i = 0; i < M; i++) {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		}


		for (int i = 1; i < table.length; i++) {
			table[i] += table[i - 1];
		}

		/*
		for (int i = 0; i < 10; i++) {
			System.out.println(table[i]);
		}
		*/

		int cnt = 0;
		for (int i = 0; i < table.length; i++) {
			if (table[i] == M) {
				cnt++;
			}
		}

		System.out.println(cnt);
	} 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[] table = new int[100100]; table new int[100100] 100100 Arrays.fill(table, 0) Arrays.fill Arrays table 0 for (int i = 0; i < M; i++) {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		} {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		} table[sc.nextInt()]++ table[sc.nextInt()] table sc.nextInt() sc.nextInt sc table[sc.nextInt() + 1]-- table[sc.nextInt() + 1] table sc.nextInt() + 1 sc.nextInt() sc.nextInt sc 1 for (int i = 1; i < table.length; i++) {
			table[i] += table[i - 1];
		} int i = 1; int i = 1; i 1 i < table.length i table.length table table.length i++ i++ i {
			table[i] += table[i - 1];
		} {
			table[i] += table[i - 1];
		} table[i] += table[i - 1] table[i] table i table[i - 1] table i - 1 i 1 int cnt = 0; cnt 0 for (int i = 0; i < table.length; i++) {
			if (table[i] == M) {
				cnt++;
			}
		} int i = 0; int i = 0; i 0 i < table.length i table.length table table.length i++ i++ i {
			if (table[i] == M) {
				cnt++;
			}
		} {
			if (table[i] == M) {
				cnt++;
			}
		} if (table[i] == M) {
				cnt++;
			} table[i] == M table[i] table i M {
				cnt++;
			} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt 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[] table = new int[100100];
		Arrays.fill(table, 0);
		for (int i = 0; i < M; i++) {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		}


		for (int i = 1; i < table.length; i++) {
			table[i] += table[i - 1];
		}

		/*
		for (int i = 0; i < 10; i++) {
			System.out.println(table[i]);
		}
		*/

		int cnt = 0;
		for (int i = 0; i < table.length; i++) {
			if (table[i] == M) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}
} 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[] table = new int[100100];
		Arrays.fill(table, 0);
		for (int i = 0; i < M; i++) {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		}


		for (int i = 1; i < table.length; i++) {
			table[i] += table[i - 1];
		}

		/*
		for (int i = 0; i < 10; i++) {
			System.out.println(table[i]);
		}
		*/

		int cnt = 0;
		for (int i = 0; i < table.length; i++) {
			if (table[i] == M) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}
} Main
import java.util.Arrays;
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[] table = new int[100100];
		Arrays.fill(table, 0);
		for (int i = 0; i < M; i++) {
			table[sc.nextInt()]++;
			table[sc.nextInt() + 1]--;
		}


		for (int i = 1; i < table.length; i++) {
			table[i] += table[i - 1];
		}

		/*
		for (int i = 0; i < 10; i++) {
			System.out.println(table[i]);
		}
		*/

		int cnt = 0;
		for (int i = 0; i < table.length; i++) {
			if (table[i] == M) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}
}
