import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int card = sc.nextInt();
		int gate = sc.nextInt();
		int count = 0;
		int flag = 0;
		ArrayList<Integer> array = new ArrayList<Integer>(10000);
		for (int i = 0; i < gate * 2; i++) {
			array.add(sc.nextInt());
		}
		int max=0;
			for(int i=0;i<gate*2;i+=2) {
				if(array.get(i)>=max) max=array.get(i);
			}

		int min=array.get(1);
			for(int i=1;i<gate*2;i+=2) {
				if(array.get(i)<=min) min=array.get(i);
			}

			for(int i=1;i<=card;i++) {
				if(i>=max&&i<=min) {
					count++;
				}
			}


		System.out.println(count);

	}
}
 import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int card = sc.nextInt();
		int gate = sc.nextInt();
		int count = 0;
		int flag = 0;
		ArrayList<Integer> array = new ArrayList<Integer>(10000);
		for (int i = 0; i < gate * 2; i++) {
			array.add(sc.nextInt());
		}
		int max=0;
			for(int i=0;i<gate*2;i+=2) {
				if(array.get(i)>=max) max=array.get(i);
			}

		int min=array.get(1);
			for(int i=1;i<gate*2;i+=2) {
				if(array.get(i)<=min) min=array.get(i);
			}

			for(int i=1;i<=card;i++) {
				if(i>=max&&i<=min) {
					count++;
				}
			}


		System.out.println(count);

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int card = sc.nextInt();
		int gate = sc.nextInt();
		int count = 0;
		int flag = 0;
		ArrayList<Integer> array = new ArrayList<Integer>(10000);
		for (int i = 0; i < gate * 2; i++) {
			array.add(sc.nextInt());
		}
		int max=0;
			for(int i=0;i<gate*2;i+=2) {
				if(array.get(i)>=max) max=array.get(i);
			}

		int min=array.get(1);
			for(int i=1;i<gate*2;i+=2) {
				if(array.get(i)<=min) min=array.get(i);
			}

			for(int i=1;i<=card;i++) {
				if(i>=max&&i<=min) {
					count++;
				}
			}


		System.out.println(count);

	} main {
		Scanner sc = new Scanner(System.in);

		int card = sc.nextInt();
		int gate = sc.nextInt();
		int count = 0;
		int flag = 0;
		ArrayList<Integer> array = new ArrayList<Integer>(10000);
		for (int i = 0; i < gate * 2; i++) {
			array.add(sc.nextInt());
		}
		int max=0;
			for(int i=0;i<gate*2;i+=2) {
				if(array.get(i)>=max) max=array.get(i);
			}

		int min=array.get(1);
			for(int i=1;i<gate*2;i+=2) {
				if(array.get(i)<=min) min=array.get(i);
			}

			for(int i=1;i<=card;i++) {
				if(i>=max&&i<=min) {
					count++;
				}
			}


		System.out.println(count);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int card = sc.nextInt(); card sc.nextInt() sc.nextInt sc int gate = sc.nextInt(); gate sc.nextInt() sc.nextInt sc int count = 0; count 0 int flag = 0; flag 0 ArrayList<Integer> array = new ArrayList<Integer>(10000); array new ArrayList<Integer>(10000) for (int i = 0; i < gate * 2; i++) {
			array.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < gate * 2 i gate * 2 gate 2 i++ i++ i {
			array.add(sc.nextInt());
		} {
			array.add(sc.nextInt());
		} array.add(sc.nextInt()) array.add array sc.nextInt() sc.nextInt sc int max=0; max 0 for(int i=0;i<gate*2;i+=2) {
				if(array.get(i)>=max) max=array.get(i);
			} int i=0; int i=0; i 0 i<gate*2 i gate*2 gate 2 i+=2 i+=2 i 2 {
				if(array.get(i)>=max) max=array.get(i);
			} {
				if(array.get(i)>=max) max=array.get(i);
			} if(array.get(i)>=max) max=array.get(i); array.get(i)>=max array.get(i) array.get array i max max=array.get(i) max array.get(i) array.get array i int min=array.get(1); min array.get(1) array.get array 1 for(int i=1;i<gate*2;i+=2) {
				if(array.get(i)<=min) min=array.get(i);
			} int i=1; int i=1; i 1 i<gate*2 i gate*2 gate 2 i+=2 i+=2 i 2 {
				if(array.get(i)<=min) min=array.get(i);
			} {
				if(array.get(i)<=min) min=array.get(i);
			} if(array.get(i)<=min) min=array.get(i); array.get(i)<=min array.get(i) array.get array i min min=array.get(i) min array.get(i) array.get array i for(int i=1;i<=card;i++) {
				if(i>=max&&i<=min) {
					count++;
				}
			} int i=1; int i=1; i 1 i<=card i card i++ i++ i {
				if(i>=max&&i<=min) {
					count++;
				}
			} {
				if(i>=max&&i<=min) {
					count++;
				}
			} if(i>=max&&i<=min) {
					count++;
				} i>=max&&i<=min i>=max i max i<=min i min {
					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 card = sc.nextInt();
		int gate = sc.nextInt();
		int count = 0;
		int flag = 0;
		ArrayList<Integer> array = new ArrayList<Integer>(10000);
		for (int i = 0; i < gate * 2; i++) {
			array.add(sc.nextInt());
		}
		int max=0;
			for(int i=0;i<gate*2;i+=2) {
				if(array.get(i)>=max) max=array.get(i);
			}

		int min=array.get(1);
			for(int i=1;i<gate*2;i+=2) {
				if(array.get(i)<=min) min=array.get(i);
			}

			for(int i=1;i<=card;i++) {
				if(i>=max&&i<=min) {
					count++;
				}
			}


		System.out.println(count);

	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int card = sc.nextInt();
		int gate = sc.nextInt();
		int count = 0;
		int flag = 0;
		ArrayList<Integer> array = new ArrayList<Integer>(10000);
		for (int i = 0; i < gate * 2; i++) {
			array.add(sc.nextInt());
		}
		int max=0;
			for(int i=0;i<gate*2;i+=2) {
				if(array.get(i)>=max) max=array.get(i);
			}

		int min=array.get(1);
			for(int i=1;i<gate*2;i+=2) {
				if(array.get(i)<=min) min=array.get(i);
			}

			for(int i=1;i<=card;i++) {
				if(i>=max&&i<=min) {
					count++;
				}
			}


		System.out.println(count);

	}
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int card = sc.nextInt();
		int gate = sc.nextInt();
		int count = 0;
		int flag = 0;
		ArrayList<Integer> array = new ArrayList<Integer>(10000);
		for (int i = 0; i < gate * 2; i++) {
			array.add(sc.nextInt());
		}
		int max=0;
			for(int i=0;i<gate*2;i+=2) {
				if(array.get(i)>=max) max=array.get(i);
			}

		int min=array.get(1);
			for(int i=1;i<gate*2;i+=2) {
				if(array.get(i)<=min) min=array.get(i);
			}

			for(int i=1;i<=card;i++) {
				if(i>=max&&i<=min) {
					count++;
				}
			}


		System.out.println(count);

	}
}

