import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		//Logic
		int answerL = 0;
		int answerR = N;

		for(int i = 0; i < M ; i++) {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		}

		//Output
		int answer = answerR - answerL + 1;

		System.out.println(Math.max(answer, 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 = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		//Logic
		int answerL = 0;
		int answerR = N;

		for(int i = 0; i < M ; i++) {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		}

		//Output
		int answer = answerR - answerL + 1;

		System.out.println(Math.max(answer, 0));

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		//Logic
		int answerL = 0;
		int answerR = N;

		for(int i = 0; i < M ; i++) {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		}

		//Output
		int answer = answerR - answerL + 1;

		System.out.println(Math.max(answer, 0));

	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		//Logic
		int answerL = 0;
		int answerR = N;

		for(int i = 0; i < M ; i++) {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		}

		//Output
		int answer = answerR - answerL + 1;

		System.out.println(Math.max(answer, 0));

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int M = Integer.parseInt(sc.next()); M Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M for(int i = 0 ; i < M ; i++) {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		} int i = 0 ; int i = 0 ; i 0 i < M i M i++ i++ i {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		} {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		} L[i] = Integer.parseInt(sc.next()) L[i] L i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc R[i] = Integer.parseInt(sc.next()) R[i] R i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int answerL = 0; answerL 0 int answerR = N; answerR N for(int i = 0; i < M ; i++) {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		} {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		} answerL = Math.max(answerL, L[i]) answerL Math.max(answerL, L[i]) Math.max Math answerL L[i] L i answerR = Math.min(answerR, R[i]) answerR Math.min(answerR, R[i]) Math.min Math answerR R[i] R i int answer = answerR - answerL + 1; answer answerR - answerL + 1 answerR - answerL answerR answerL 1 System.out.println(Math.max(answer, 0)) System.out.println System.out System System.out Math.max(answer, 0) Math.max Math answer 0 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		//Logic
		int answerL = 0;
		int answerR = N;

		for(int i = 0; i < M ; i++) {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		}

		//Output
		int answer = answerR - answerL + 1;

		System.out.println(Math.max(answer, 0));

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		//Logic
		int answerL = 0;
		int answerR = N;

		for(int i = 0; i < M ; i++) {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		}

		//Output
		int answer = answerR - answerL + 1;

		System.out.println(Math.max(answer, 0));

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		int[] L = new int[M];
		int[] R = new int[M];

		for(int i = 0 ; i < M ; i++) {
			L[i] = Integer.parseInt(sc.next());
			R[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		//Logic
		int answerL = 0;
		int answerR = N;

		for(int i = 0; i < M ; i++) {
			answerL = Math.max(answerL, L[i]);
			answerR = Math.min(answerR, R[i]);
		}

		//Output
		int answer = answerR - answerL + 1;

		System.out.println(Math.max(answer, 0));

	}

}
