import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		int N = conv(line[0]); int M = conv(line[1]);
		int[][] gates = new int[M][2];
		for(int i = 0; i < M; i++) {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		}
		int Lmax = 0; int Rmin = Integer.MAX_VALUE;
		for(int[] range : gates) {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		}
		int valid = Rmin - Lmax;
		if(valid < 0) {
			System.out.println(0);
			return;
		}
		System.out.println(valid + 1);
	}
	public static int conv(String s) {
		return Integer.valueOf(s);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		int N = conv(line[0]); int M = conv(line[1]);
		int[][] gates = new int[M][2];
		for(int i = 0; i < M; i++) {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		}
		int Lmax = 0; int Rmin = Integer.MAX_VALUE;
		for(int[] range : gates) {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		}
		int valid = Rmin - Lmax;
		if(valid < 0) {
			System.out.println(0);
			return;
		}
		System.out.println(valid + 1);
	}
	public static int conv(String s) {
		return Integer.valueOf(s);
	}
} Main public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		int N = conv(line[0]); int M = conv(line[1]);
		int[][] gates = new int[M][2];
		for(int i = 0; i < M; i++) {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		}
		int Lmax = 0; int Rmin = Integer.MAX_VALUE;
		for(int[] range : gates) {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		}
		int valid = Rmin - Lmax;
		if(valid < 0) {
			System.out.println(0);
			return;
		}
		System.out.println(valid + 1);
	} main {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		int N = conv(line[0]); int M = conv(line[1]);
		int[][] gates = new int[M][2];
		for(int i = 0; i < M; i++) {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		}
		int Lmax = 0; int Rmin = Integer.MAX_VALUE;
		for(int[] range : gates) {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		}
		int valid = Rmin - Lmax;
		if(valid < 0) {
			System.out.println(0);
			return;
		}
		System.out.println(valid + 1);
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) String[] line = in.readLine().split(" "); line in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int N = conv(line[0]); N conv(line[0]) conv line[0] line 0 int M = conv(line[1]); M conv(line[1]) conv line[1] line 1 int[][] gates = new int[M][2]; gates new int[M][2] M 2 for(int i = 0; i < M; i++) {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		} {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		} line = in.readLine().split(" ") line in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " gates[i][0] = conv(line[0]) gates[i][0] gates[i] gates i 0 conv(line[0]) conv line[0] line 0 gates[i][1] = conv(line[1]) gates[i][1] gates[i] gates i 1 conv(line[1]) conv line[1] line 1 int Lmax = 0; Lmax 0 int Rmin = Integer.MAX_VALUE; Rmin Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int[] range : gates) {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		} int[] range gates {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		} {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		} if(Lmax < range[0]) {
				Lmax = range[0];
			} Lmax < range[0] Lmax range[0] range 0 {
				Lmax = range[0];
			} Lmax = range[0] Lmax range[0] range 0 if(range[1] < Rmin) {
				Rmin = range[1];
			} range[1] < Rmin range[1] range 1 Rmin {
				Rmin = range[1];
			} Rmin = range[1] Rmin range[1] range 1 int valid = Rmin - Lmax; valid Rmin - Lmax Rmin Lmax if(valid < 0) {
			System.out.println(0);
			return;
		} valid < 0 valid 0 {
			System.out.println(0);
			return;
		} System.out.println(0) System.out.println System.out System System.out 0 return; System.out.println(valid + 1) System.out.println System.out System System.out valid + 1 valid 1 String[] args args public static int conv(String s) {
		return Integer.valueOf(s);
	} conv {
		return Integer.valueOf(s);
	} return Integer.valueOf(s); Integer.valueOf(s) Integer.valueOf Integer s String s s public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		int N = conv(line[0]); int M = conv(line[1]);
		int[][] gates = new int[M][2];
		for(int i = 0; i < M; i++) {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		}
		int Lmax = 0; int Rmin = Integer.MAX_VALUE;
		for(int[] range : gates) {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		}
		int valid = Rmin - Lmax;
		if(valid < 0) {
			System.out.println(0);
			return;
		}
		System.out.println(valid + 1);
	}
	public static int conv(String s) {
		return Integer.valueOf(s);
	}
} public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		int N = conv(line[0]); int M = conv(line[1]);
		int[][] gates = new int[M][2];
		for(int i = 0; i < M; i++) {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		}
		int Lmax = 0; int Rmin = Integer.MAX_VALUE;
		for(int[] range : gates) {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		}
		int valid = Rmin - Lmax;
		if(valid < 0) {
			System.out.println(0);
			return;
		}
		System.out.println(valid + 1);
	}
	public static int conv(String s) {
		return Integer.valueOf(s);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		int N = conv(line[0]); int M = conv(line[1]);
		int[][] gates = new int[M][2];
		for(int i = 0; i < M; i++) {
			line = in.readLine().split(" ");
			gates[i][0] = conv(line[0]); gates[i][1] = conv(line[1]);
		}
		int Lmax = 0; int Rmin = Integer.MAX_VALUE;
		for(int[] range : gates) {
			if(Lmax < range[0]) {
				Lmax = range[0];
			}
			if(range[1] < Rmin) {
				Rmin = range[1];
			}
		}
		int valid = Rmin - Lmax;
		if(valid < 0) {
			System.out.println(0);
			return;
		}
		System.out.println(valid + 1);
	}
	public static int conv(String s) {
		return Integer.valueOf(s);
	}
}