

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int N = Integer.parseInt(lines[0]);
		int M = Integer.parseInt(lines[1]);
		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		}

		int Left = L[0];
		int Right = R[0];
		for(int i = 0; i < M; i++) {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		}

		if(Right- Left < 0) {
			System.out.println(0);
		}else {
			System.out.println(Right - Left + 1);
		}

	}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int N = Integer.parseInt(lines[0]);
		int M = Integer.parseInt(lines[1]);
		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		}

		int Left = L[0];
		int Right = R[0];
		for(int i = 0; i < M; i++) {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		}

		if(Right- Left < 0) {
			System.out.println(0);
		}else {
			System.out.println(Right - Left + 1);
		}

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int N = Integer.parseInt(lines[0]);
		int M = Integer.parseInt(lines[1]);
		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		}

		int Left = L[0];
		int Right = R[0];
		for(int i = 0; i < M; i++) {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		}

		if(Right- Left < 0) {
			System.out.println(0);
		}else {
			System.out.println(Right - Left + 1);
		}

	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int N = Integer.parseInt(lines[0]);
		int M = Integer.parseInt(lines[1]);
		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		}

		int Left = L[0];
		int Right = R[0];
		for(int i = 0; i < M; i++) {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		}

		if(Right- Left < 0) {
			System.out.println(0);
		}else {
			System.out.println(Right - Left + 1);
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] lines = line.split(" "); lines line.split(" ") line.split line " " int N = Integer.parseInt(lines[0]); N Integer.parseInt(lines[0]) Integer.parseInt Integer lines[0] lines 0 int M = Integer.parseInt(lines[1]); M Integer.parseInt(lines[1]) Integer.parseInt Integer lines[1] lines 1 int[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M for(int i = 0 ; i < M ; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		} int i = 0 ; int i = 0 ; i 0 i < M i M i++ i++ i {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		} {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		} line = sc.nextLine() line sc.nextLine() sc.nextLine sc lines = line.split(" ") lines line.split(" ") line.split line " " L[i] = Integer.parseInt(lines[0]) L[i] L i Integer.parseInt(lines[0]) Integer.parseInt Integer lines[0] lines 0 R[i] = Integer.parseInt(lines[1]) R[i] R i Integer.parseInt(lines[1]) Integer.parseInt Integer lines[1] lines 1 int Left = L[0]; Left L[0] L 0 int Right = R[0]; Right R[0] R 0 for(int i = 0; i < M; i++) {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		} {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		} if(Left < L[i]) {
				Left = L[i];
			} Left < L[i] Left L[i] L i {
				Left = L[i];
			} Left = L[i] Left L[i] L i if(Right > R[i]) {
				Right = R[i];
			} Right > R[i] Right R[i] R i {
				Right = R[i];
			} Right = R[i] Right R[i] R i if(Right- Left < 0) {
			System.out.println(0);
		}else {
			System.out.println(Right - Left + 1);
		} Right- Left < 0 Right- Left Right Left 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(Right - Left + 1);
		} System.out.println(Right - Left + 1) System.out.println System.out System System.out Right - Left + 1 Right - Left Right Left 1 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int N = Integer.parseInt(lines[0]);
		int M = Integer.parseInt(lines[1]);
		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		}

		int Left = L[0];
		int Right = R[0];
		for(int i = 0; i < M; i++) {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		}

		if(Right- Left < 0) {
			System.out.println(0);
		}else {
			System.out.println(Right - Left + 1);
		}

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int N = Integer.parseInt(lines[0]);
		int M = Integer.parseInt(lines[1]);
		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		}

		int Left = L[0];
		int Right = R[0];
		for(int i = 0; i < M; i++) {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		}

		if(Right- Left < 0) {
			System.out.println(0);
		}else {
			System.out.println(Right - Left + 1);
		}

	}

} Main


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int N = Integer.parseInt(lines[0]);
		int M = Integer.parseInt(lines[1]);
		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			L[i] = Integer.parseInt(lines[0]);
			R[i] = Integer.parseInt(lines[1]);
		}

		int Left = L[0];
		int Right = R[0];
		for(int i = 0; i < M; i++) {
			if(Left < L[i]) {
				Left = L[i];
			}
			if(Right > R[i]) {
				Right = R[i];
			}
		}

		if(Right- Left < 0) {
			System.out.println(0);
		}else {
			System.out.println(Right - Left + 1);
		}

	}

}
