import 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[] arr = new int[n];
		for (int i = 0; i < m; i++) {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		}
		System.out.print(count);
	}
} import java.util.*; util.* java public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < m; i++) {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		}
		System.out.print(count);
	}
} Main public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < m; i++) {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		}
		System.out.print(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < m; i++) {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		}
		System.out.print(count);
	} 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[] arr = new int[n]; arr new int[n] n for (int i = 0; i < m; i++) {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		} {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		} int left = sc.nextInt() - 1; left sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int right = sc.nextInt() - 1; right sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 arr[left]++ arr[left] arr left if (right < n - 1) {
				arr[right + 1]--;
			} right < n - 1 right n - 1 n 1 {
				arr[right + 1]--;
			} arr[right + 1]-- arr[right + 1] arr right + 1 right 1 int count = 0; count 0 for (int i = 0; i < n; i++) {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		} {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		} if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			} i != 0 i 0 {
				arr[i] = arr[i - 1] + arr[i];
			} arr[i] = arr[i - 1] + arr[i] arr[i] arr i arr[i - 1] + arr[i] arr[i - 1] arr i - 1 i 1 arr[i] arr i if (arr[i] == m) {
				count++;
			} arr[i] == m arr[i] arr i m {
				count++;
			} count++ count System.out.print(count) System.out.print System.out System System.out count 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[] arr = new int[n];
		for (int i = 0; i < m; i++) {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		}
		System.out.print(count);
	}
} public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < m; i++) {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		}
		System.out.print(count);
	}
} Main
import 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[] arr = new int[n];
		for (int i = 0; i < m; i++) {
			int left = sc.nextInt() - 1;
			int right = sc.nextInt() - 1;
			arr[left]++;
			if (right < n - 1) {
				arr[right + 1]--;
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (i != 0) {
				arr[i] = arr[i - 1] + arr[i];
			}
			if (arr[i] == m) {
				count++;
			}
		}
		System.out.print(count);
	}
}
