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[] a = new int[n+2];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		}

		System.out.println(ans);

		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[] a = new int[n+2];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		}

		System.out.println(ans);

		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 値を取得
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n+2];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		}

		System.out.println(ans);

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		// 値を取得
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n+2];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		}

		System.out.println(ans);

		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[] a = new int[n+2]; a new int[n+2] n+2 n 2 int ans = 0; ans 0 for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc a[l]++ a[l] a l a[r + 1]-- a[r + 1] a r + 1 r 1 for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		} {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		} if (a[i] == m) {
				ans++;
			} a[i] == m a[i] a i m {
				ans++;
			} ans++ ans a[i + 1] += a[i] a[i + 1] a i + 1 i 1 a[i] a i System.out.println(ans) System.out.println System.out System System.out ans 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[] a = new int[n+2];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		}

		System.out.println(ans);

		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[] a = new int[n+2];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		}

		System.out.println(ans);

		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[] a = new int[n+2];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		}

		System.out.println(ans);

		sc.close();
	}
}
