import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int min = -1;
		int max = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		}
		System.out.println(max - min + 1 > 0 ? max - min + 1 : 0);
		in.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int min = -1;
		int max = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		}
		System.out.println(max - min + 1 > 0 ? max - min + 1 : 0);
		in.close();
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int min = -1;
		int max = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		}
		System.out.println(max - min + 1 > 0 ? max - min + 1 : 0);
		in.close();
	} main {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int min = -1;
		int max = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		}
		System.out.println(max - min + 1 > 0 ? max - min + 1 : 0);
		in.close();
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in int M = in.nextInt(); M in.nextInt() in.nextInt in int min = -1; min -1 1 int max = Integer.MAX_VALUE; max Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		} {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		} min = Math.max(min, in.nextInt()) min Math.max(min, in.nextInt()) Math.max Math min in.nextInt() in.nextInt in max = Math.min(max, in.nextInt()) max Math.min(max, in.nextInt()) Math.min Math max in.nextInt() in.nextInt in System.out.println(max - min + 1 > 0 ? max - min + 1 : 0) System.out.println System.out System System.out max - min + 1 > 0 ? max - min + 1 : 0 max - min + 1 > 0 max - min + 1 max - min max min 1 0 max - min + 1 max - min max min 1 0 in.close() in.close in String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int min = -1;
		int max = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		}
		System.out.println(max - min + 1 > 0 ? max - min + 1 : 0);
		in.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int min = -1;
		int max = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		}
		System.out.println(max - min + 1 > 0 ? max - min + 1 : 0);
		in.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int min = -1;
		int max = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		}
		System.out.println(max - min + 1 > 0 ? max - min + 1 : 0);
		in.close();
	}
}