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 data[][] = new int[m][2];

		for (int i = 0; i < m; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}

		int min = data[0][0];
		int max = data[0][1];

		for (int i = 1; i < m; i++) {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		}

		int result = max - min + 1;
		
		if (result < 0) {
			System.out.println(0);
		} else {
			System.out.println(result);
		}
	}
} 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 data[][] = new int[m][2];

		for (int i = 0; i < m; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}

		int min = data[0][0];
		int max = data[0][1];

		for (int i = 1; i < m; i++) {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		}

		int result = max - min + 1;
		
		if (result < 0) {
			System.out.println(0);
		} else {
			System.out.println(result);
		}
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int data[][] = new int[m][2];

		for (int i = 0; i < m; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}

		int min = data[0][0];
		int max = data[0][1];

		for (int i = 1; i < m; i++) {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		}

		int result = max - min + 1;
		
		if (result < 0) {
			System.out.println(0);
		} else {
			System.out.println(result);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int data[][] = new int[m][2];

		for (int i = 0; i < m; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}

		int min = data[0][0];
		int max = data[0][1];

		for (int i = 1; i < m; i++) {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		}

		int result = max - min + 1;
		
		if (result < 0) {
			System.out.println(0);
		} else {
			System.out.println(result);
		}
	} 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 data[][] = new int[m][2]; data new int[m][2] m 2 for (int i = 0; i < m; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		} {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		} data[i][0] = sc.nextInt() data[i][0] data[i] data i 0 sc.nextInt() sc.nextInt sc data[i][1] = sc.nextInt() data[i][1] data[i] data i 1 sc.nextInt() sc.nextInt sc int min = data[0][0]; min data[0][0] data[0] data 0 0 int max = data[0][1]; max data[0][1] data[0] data 0 1 for (int i = 1; i < m; i++) {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		} int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		} {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		} if (min < data[i][0]) {
				min = data[i][0];
			} min < data[i][0] min data[i][0] data[i] data i 0 {
				min = data[i][0];
			} min = data[i][0] min data[i][0] data[i] data i 0 if (max > data[i][1]) {
				max = data[i][1];
			} max > data[i][1] max data[i][1] data[i] data i 1 {
				max = data[i][1];
			} max = data[i][1] max data[i][1] data[i] data i 1 int result = max - min + 1; result max - min + 1 max - min max min 1 if (result < 0) {
			System.out.println(0);
		} else {
			System.out.println(result);
		} result < 0 result 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(result);
		} System.out.println(result) System.out.println System.out System System.out result 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 data[][] = new int[m][2];

		for (int i = 0; i < m; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}

		int min = data[0][0];
		int max = data[0][1];

		for (int i = 1; i < m; i++) {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		}

		int result = max - min + 1;
		
		if (result < 0) {
			System.out.println(0);
		} else {
			System.out.println(result);
		}
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int data[][] = new int[m][2];

		for (int i = 0; i < m; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}

		int min = data[0][0];
		int max = data[0][1];

		for (int i = 1; i < m; i++) {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		}

		int result = max - min + 1;
		
		if (result < 0) {
			System.out.println(0);
		} else {
			System.out.println(result);
		}
	}
} 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 data[][] = new int[m][2];

		for (int i = 0; i < m; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}

		int min = data[0][0];
		int max = data[0][1];

		for (int i = 1; i < m; i++) {
			if (min < data[i][0]) {
				min = data[i][0];
			}
			if (max > data[i][1]) {
				max = data[i][1];
			}
		}

		int result = max - min + 1;
		
		if (result < 0) {
			System.out.println(0);
		} else {
			System.out.println(result);
		}
	}
}