import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;

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

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

	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;

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

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

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;

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

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

	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;

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

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

	} 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 = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int i = 0; i < M; i++) {
			max = Math.max(max, sc.nextInt());
			min = Math.min(min, sc.nextInt());
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			max = Math.max(max, sc.nextInt());
			min = Math.min(min, sc.nextInt());
		} {
			max = Math.max(max, sc.nextInt());
			min = Math.min(min, sc.nextInt());
		} max = Math.max(max, sc.nextInt()) max Math.max(max, sc.nextInt()) Math.max Math max sc.nextInt() sc.nextInt sc min = Math.min(min, sc.nextInt()) min Math.min(min, sc.nextInt()) Math.min Math min sc.nextInt() sc.nextInt sc if (min < max) {
			System.out.println(0);
		} else {
			System.out.println(min - max + 1);
		} min < max min max {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(min - max + 1);
		} System.out.println(min - max + 1) System.out.println System.out System System.out min - max + 1 min - max min max 1 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;

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

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

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;

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

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

	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;

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

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

	}
}
