import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int min = 1;
		int max = in.nextInt();
		int gate = in.nextInt();
		int cch;
		for (int i = 0; i < gate; i++) {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		}
		in.close();
		int ans = max - min + 1;
		if (ans < 0) ans = 0;
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int min = 1;
		int max = in.nextInt();
		int gate = in.nextInt();
		int cch;
		for (int i = 0; i < gate; i++) {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		}
		in.close();
		int ans = max - min + 1;
		if (ans < 0) ans = 0;
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int min = 1;
		int max = in.nextInt();
		int gate = in.nextInt();
		int cch;
		for (int i = 0; i < gate; i++) {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		}
		in.close();
		int ans = max - min + 1;
		if (ans < 0) ans = 0;
		System.out.println(ans);
	} main {
		Scanner in = new Scanner(System.in);
		int min = 1;
		int max = in.nextInt();
		int gate = in.nextInt();
		int cch;
		for (int i = 0; i < gate; i++) {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		}
		in.close();
		int ans = max - min + 1;
		if (ans < 0) ans = 0;
		System.out.println(ans);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int min = 1; min 1 int max = in.nextInt(); max in.nextInt() in.nextInt in int gate = in.nextInt(); gate in.nextInt() in.nextInt in int cch; cch for (int i = 0; i < gate; i++) {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		} int i = 0; int i = 0; i 0 i < gate i gate i++ i++ i {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		} {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		} for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			} int j = 0; int j = 0; j 0 j < 2 j 2 j++ j++ j {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			} {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			} cch = in.nextInt() cch in.nextInt() in.nextInt in if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				} j == 0 j 0 {
					if (min < cch) min = cch;
				} if (min < cch) min = cch; min < cch min cch min = cch min cch {
					if (max > cch) max = cch;
				} if (max > cch) max = cch; max > cch max cch max = cch max cch in.close() in.close in int ans = max - min + 1; ans max - min + 1 max - min max min 1 if (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) {
		Scanner in = new Scanner(System.in);
		int min = 1;
		int max = in.nextInt();
		int gate = in.nextInt();
		int cch;
		for (int i = 0; i < gate; i++) {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		}
		in.close();
		int ans = max - min + 1;
		if (ans < 0) ans = 0;
		System.out.println(ans);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int min = 1;
		int max = in.nextInt();
		int gate = in.nextInt();
		int cch;
		for (int i = 0; i < gate; i++) {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		}
		in.close();
		int ans = max - min + 1;
		if (ans < 0) ans = 0;
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int min = 1;
		int max = in.nextInt();
		int gate = in.nextInt();
		int cch;
		for (int i = 0; i < gate; i++) {
			for (int j = 0; j < 2; j++) {
				cch = in.nextInt();
				if (j == 0) {
					if (min < cch) min = cch;
				} else {
					if (max > cch) max = cch;
				}
			}
		}
		in.close();
		int ans = max - min + 1;
		if (ans < 0) ans = 0;
		System.out.println(ans);
	}
}