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 count = 0;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int judge1 = -1;
		int judge2 = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		}
		for(int i = 0; i < n; i++) {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		}
		System.out.println(count);
	}
} 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 count = 0;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int judge1 = -1;
		int judge2 = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		}
		for(int i = 0; i < n; i++) {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int count = 0;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int judge1 = -1;
		int judge2 = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		}
		for(int i = 0; i < n; i++) {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int count = 0;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int judge1 = -1;
		int judge2 = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		}
		for(int i = 0; i < n; i++) {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		}
		System.out.println(count);
	} 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 count = 0; count 0 int[] key = new int[n]; key new int[n] n for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		} int i = 1; int i = 1; i 1 i <=n i n i++ i++ i {
			key[i-1] = i;
		} {
			key[i-1] = i;
		} key[i-1] = i key[i-1] key i-1 i 1 i int judge1 = -1; judge1 -1 1 int judge2 = Integer.MAX_VALUE; judge2 Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0; i < m; i++) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		} {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		} int temp1 = sc.nextInt(); temp1 sc.nextInt() sc.nextInt sc int temp2 = sc.nextInt(); temp2 sc.nextInt() sc.nextInt sc if(temp1 > judge1) {
				judge1 = temp1;
			} temp1 > judge1 temp1 judge1 {
				judge1 = temp1;
			} judge1 = temp1 judge1 temp1 if(temp2 <judge2) {
				judge2 = temp2;
			} temp2 <judge2 temp2 judge2 {
				judge2 = temp2;
			} judge2 = temp2 judge2 temp2 for(int i = 0; i < n; i++) {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		} {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		} if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			} key[i] >= judge1 && key[i] <= judge2 key[i] >= judge1 key[i] key i judge1 key[i] <= judge2 key[i] key i judge2 {
				count++;
			} count++ count System.out.println(count) System.out.println System.out System System.out count 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 count = 0;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int judge1 = -1;
		int judge2 = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		}
		for(int i = 0; i < n; i++) {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		}
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int count = 0;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int judge1 = -1;
		int judge2 = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		}
		for(int i = 0; i < n; i++) {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		}
		System.out.println(count);
	}
} 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 count = 0;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int judge1 = -1;
		int judge2 = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++) {
			int temp1 = sc.nextInt();
			int temp2 = sc.nextInt();
			if(temp1 > judge1) {
				judge1 = temp1;
			}
			if(temp2 <judge2) {
				judge2 = temp2;
			}
		}
		for(int i = 0; i < n; i++) {
			if(key[i] >= judge1 && key[i] <= judge2) {
				count++;
			}
		}
		System.out.println(count);
	}
}