import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		int min = 1;
		int max = scan.nextInt();
		int num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		}

		// answer
		if (max - min < 0) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		int min = 1;
		int max = scan.nextInt();
		int num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		}

		// answer
		if (max - min < 0) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		}

	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		int min = 1;
		int max = scan.nextInt();
		int num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		}

		// answer
		if (max - min < 0) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		}

	} main {
		Scanner scan = new Scanner(System.in);

		// input
		int min = 1;
		int max = scan.nextInt();
		int num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		}

		// answer
		if (max - min < 0) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int min = 1; min 1 int max = scan.nextInt(); max scan.nextInt() scan.nextInt scan int num = scan.nextInt(); num scan.nextInt() scan.nextInt scan for (int i = 0; i < num; i++) {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		} {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		} int left = scan.nextInt(); left scan.nextInt() scan.nextInt scan int right = scan.nextInt(); right scan.nextInt() scan.nextInt scan if (left > min) {
				min = left;
			} left > min left min {
				min = left;
			} min = left min left if (right < max) {
				max = right;
			} right < max right max {
				max = right;
			} max = right max right if (max - min < 0) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		} max - min < 0 max - min max min 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(max - min + 1);
		} System.out.println(max - min + 1) System.out.println System.out System System.out max - min + 1 max - min max min 1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		int min = 1;
		int max = scan.nextInt();
		int num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		}

		// answer
		if (max - min < 0) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		}

	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		int min = 1;
		int max = scan.nextInt();
		int num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		}

		// answer
		if (max - min < 0) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		}

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		int min = 1;
		int max = scan.nextInt();
		int num = scan.nextInt();
		for (int i = 0; i < num; i++) {
			int left = scan.nextInt();
			int right = scan.nextInt();
			if (left > min) {
				min = left;
			}
			if (right < max) {
				max = right;
			}
		}

		// answer
		if (max - min < 0) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		}

	}
}
