import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 1000000;

		for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		System.out.println(Math.max(max - min + 1, 0));
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 1000000;

		for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		System.out.println(Math.max(max - min + 1, 0));
	}
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 1000000;

		for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		System.out.println(Math.max(max - min + 1, 0));
	} main {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 1000000;

		for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		System.out.println(Math.max(max - min + 1, 0));
	} 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 min = 0; min 0 int max = 1000000; max 1000000 for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		} {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		} min = Math.max(min, sc.nextInt()) min Math.max(min, sc.nextInt()) Math.max Math min sc.nextInt() sc.nextInt sc max = Math.min(max, sc.nextInt()) max Math.min(max, sc.nextInt()) Math.min Math max sc.nextInt() sc.nextInt sc System.out.println(Math.max(max - min + 1, 0)) System.out.println System.out System System.out Math.max(max - min + 1, 0) Math.max Math max - min + 1 max - min max min 1 0 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 1000000;

		for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		System.out.println(Math.max(max - min + 1, 0));
	}
} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 1000000;

		for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		System.out.println(Math.max(max - min + 1, 0));
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 1000000;

		for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		System.out.println(Math.max(max - min + 1, 0));
	}
}