import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		String[] str = br.readLine().split(" ");

		int N = Integer.parseInt(str[0]);
		int M = Integer.parseInt(str[1]);

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

		int Lmax = 0;
		int Rmin = 0;


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

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		}

		int ans = Rmin - Lmax + 1;

		if(ans > 0) {
			System.out.print(ans);
		}else {
			System.out.print(0);
		}


	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		String[] str = br.readLine().split(" ");

		int N = Integer.parseInt(str[0]);
		int M = Integer.parseInt(str[1]);

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

		int Lmax = 0;
		int Rmin = 0;


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

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		}

		int ans = Rmin - Lmax + 1;

		if(ans > 0) {
			System.out.print(ans);
		}else {
			System.out.print(0);
		}


	}

} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		String[] str = br.readLine().split(" ");

		int N = Integer.parseInt(str[0]);
		int M = Integer.parseInt(str[1]);

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

		int Lmax = 0;
		int Rmin = 0;


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

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		}

		int ans = Rmin - Lmax + 1;

		if(ans > 0) {
			System.out.print(ans);
		}else {
			System.out.print(0);
		}


	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		String[] str = br.readLine().split(" ");

		int N = Integer.parseInt(str[0]);
		int M = Integer.parseInt(str[1]);

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

		int Lmax = 0;
		int Rmin = 0;


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

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		}

		int ans = Rmin - Lmax + 1;

		if(ans > 0) {
			System.out.print(ans);
		}else {
			System.out.print(0);
		}


	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int N = Integer.parseInt(str[0]); N Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int M = Integer.parseInt(str[1]); M Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 int L[] =new int[M]; L new int[M] M int R[] =new int[M]; R new int[M] M int Lmax = 0; Lmax 0 int Rmin = 0; Rmin 0 for(int i=0;i<M;i++) {

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		} {

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		} String[] str1 = br.readLine().split(" "); str1 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " L[i] = Integer.parseInt(str1[0]) L[i] L i Integer.parseInt(str1[0]) Integer.parseInt Integer str1[0] str1 0 R[i] = Integer.parseInt(str1[1]) R[i] R i Integer.parseInt(str1[1]) Integer.parseInt Integer str1[1] str1 1 if(L[i]>Lmax) {
				Lmax = L[i];
			} L[i]>Lmax L[i] L i Lmax {
				Lmax = L[i];
			} Lmax = L[i] Lmax L[i] L i if(i == 0) {
				Rmin = R[i];
			} i == 0 i 0 {
				Rmin = R[i];
			} Rmin = R[i] Rmin R[i] R i if(R[i]<Rmin) {
				Rmin = R[i];
			} R[i]<Rmin R[i] R i Rmin {
				Rmin = R[i];
			} Rmin = R[i] Rmin R[i] R i int ans = Rmin - Lmax + 1; ans Rmin - Lmax + 1 Rmin - Lmax Rmin Lmax 1 if(ans > 0) {
			System.out.print(ans);
		}else {
			System.out.print(0);
		} ans > 0 ans 0 {
			System.out.print(ans);
		} System.out.print(ans) System.out.print System.out System System.out ans {
			System.out.print(0);
		} System.out.print(0) System.out.print System.out System System.out 0 String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		String[] str = br.readLine().split(" ");

		int N = Integer.parseInt(str[0]);
		int M = Integer.parseInt(str[1]);

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

		int Lmax = 0;
		int Rmin = 0;


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

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		}

		int ans = Rmin - Lmax + 1;

		if(ans > 0) {
			System.out.print(ans);
		}else {
			System.out.print(0);
		}


	}

} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		String[] str = br.readLine().split(" ");

		int N = Integer.parseInt(str[0]);
		int M = Integer.parseInt(str[1]);

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

		int Lmax = 0;
		int Rmin = 0;


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

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		}

		int ans = Rmin - Lmax + 1;

		if(ans > 0) {
			System.out.print(ans);
		}else {
			System.out.print(0);
		}


	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		String[] str = br.readLine().split(" ");

		int N = Integer.parseInt(str[0]);
		int M = Integer.parseInt(str[1]);

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

		int Lmax = 0;
		int Rmin = 0;


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

			String[] str1 = br.readLine().split(" ");
			L[i] = Integer.parseInt(str1[0]);
			R[i] = Integer.parseInt(str1[1]);

			if(L[i]>Lmax) {
				Lmax = L[i];
			}

			if(i == 0) {
				Rmin = R[i];
			}

			if(R[i]<Rmin) {
				Rmin = R[i];
			}
		}

		int ans = Rmin - Lmax + 1;

		if(ans > 0) {
			System.out.print(ans);
		}else {
			System.out.print(0);
		}


	}

}
