import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    long lr[][]=new long[m][2];
	    for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    }
	    scan.close();
	    long min=0;
	    long max=n;
	    for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    }

	    System.out.println((min<=max)? max-min+1:"0");

	}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    long lr[][]=new long[m][2];
	    for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    }
	    scan.close();
	    long min=0;
	    long max=n;
	    for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    }

	    System.out.println((min<=max)? max-min+1:"0");

	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    long lr[][]=new long[m][2];
	    for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    }
	    scan.close();
	    long min=0;
	    long max=n;
	    for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    }

	    System.out.println((min<=max)? max-min+1:"0");

	} main {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    long lr[][]=new long[m][2];
	    for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    }
	    scan.close();
	    long min=0;
	    long max=n;
	    for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    }

	    System.out.println((min<=max)? max-min+1:"0");

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan long lr[][]=new long[m][2]; lr new long[m][2] m 2 for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    } int i=0; int i=0; i 0 i<m i m i++ i++ i {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    } {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    } lr[i][0]=scan.nextLong() lr[i][0] lr[i] lr i 0 scan.nextLong() scan.nextLong scan lr[i][1]=scan.nextLong() lr[i][1] lr[i] lr i 1 scan.nextLong() scan.nextLong scan scan.close() scan.close scan long min=0; min 0 long max=n; max n for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    } int i=0; int i=0; i 0 i<m i m i++ i++ i {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    } {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    } if( lr[i][0] > min ) min = lr[i][0]; lr[i][0] > min lr[i][0] lr[i] lr i 0 min min = lr[i][0] min lr[i][0] lr[i] lr i 0 if( lr[i][1] < max ) max = lr[i][1]; lr[i][1] < max lr[i][1] lr[i] lr i 1 max max = lr[i][1] max lr[i][1] lr[i] lr i 1 System.out.println((min<=max)? max-min+1:"0") System.out.println System.out System System.out (min<=max)? max-min+1:"0" (min<=max) min max max-min+1 max-min max min 1 "0" String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    long lr[][]=new long[m][2];
	    for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    }
	    scan.close();
	    long min=0;
	    long max=n;
	    for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    }

	    System.out.println((min<=max)? max-min+1:"0");

	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    long lr[][]=new long[m][2];
	    for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    }
	    scan.close();
	    long min=0;
	    long max=n;
	    for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    }

	    System.out.println((min<=max)? max-min+1:"0");

	}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    long lr[][]=new long[m][2];
	    for(int i=0;i<m;i++) {
	    	lr[i][0]=scan.nextLong();
	    	lr[i][1]=scan.nextLong();
	    }
	    scan.close();
	    long min=0;
	    long max=n;
	    for(int i=0;i<m;i++) {
	    	if( lr[i][0] > min ) min = lr[i][0];
	    	if( lr[i][1] < max ) max = lr[i][1];
	    }

	    System.out.println((min<=max)? max-min+1:"0");

	}

}
