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

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int l[] = new int[m];
		int r[] = new int[m];

		int maxL = 0;
		int minR = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		}
		int ans = (minR - maxL) + 1;
		if (ans < 0) {
			ans = 0;
		}
		System.out.println(ans);
	}
} 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 IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int l[] = new int[m];
		int r[] = new int[m];

		int maxL = 0;
		int minR = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		}
		int ans = (minR - maxL) + 1;
		if (ans < 0) {
			ans = 0;
		}
		System.out.println(ans);
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int l[] = new int[m];
		int r[] = new int[m];

		int maxL = 0;
		int minR = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		}
		int ans = (minR - maxL) + 1;
		if (ans < 0) {
			ans = 0;
		}
		System.out.println(ans);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int l[] = new int[m];
		int r[] = new int[m];

		int maxL = 0;
		int minR = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		}
		int ans = (minR - maxL) + 1;
		if (ans < 0) {
			ans = 0;
		}
		System.out.println(ans);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str[] = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int m = Integer.parseInt(str[1]); m Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 int l[] = new int[m]; l new int[m] m int r[] = new int[m]; r new int[m] m int maxL = 0; maxL 0 int minR = Integer.MAX_VALUE; minR Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		} {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		} str = br.readLine().split(" ") str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " l[i] = Integer.parseInt(str[0]) l[i] l i Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 r[i] = Integer.parseInt(str[1]) r[i] r i Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 maxL = Math.max(maxL, l[i]) maxL Math.max(maxL, l[i]) Math.max Math maxL l[i] l i minR = Math.min(minR, r[i]) minR Math.min(minR, r[i]) Math.min Math minR r[i] r i int ans = (minR - maxL) + 1; ans (minR - maxL) + 1 (minR - maxL) minR maxL 1 if (ans < 0) {
			ans = 0;
		} ans < 0 ans 0 {
			ans = 0;
		} ans = 0 ans 0 System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int l[] = new int[m];
		int r[] = new int[m];

		int maxL = 0;
		int minR = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		}
		int ans = (minR - maxL) + 1;
		if (ans < 0) {
			ans = 0;
		}
		System.out.println(ans);
	}
} public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int l[] = new int[m];
		int r[] = new int[m];

		int maxL = 0;
		int minR = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		}
		int ans = (minR - maxL) + 1;
		if (ans < 0) {
			ans = 0;
		}
		System.out.println(ans);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int l[] = new int[m];
		int r[] = new int[m];

		int maxL = 0;
		int minR = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			l[i] = Integer.parseInt(str[0]);
			r[i] = Integer.parseInt(str[1]);
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
		}
		int ans = (minR - maxL) + 1;
		if (ans < 0) {
			ans = 0;
		}
		System.out.println(ans);
	}
}