import 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[] l = new int[m];
        int[] r = new int[m];

        for(int i=0; i<m; i++){
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        }
        int lMax = l[0];
        int rMin = r[0];
        for(int i=1; i<m; i++){
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        }
        if(rMin-lMax<0) System.out.println("0");
        else System.out.println(rMin-lMax+1);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];

        for(int i=0; i<m; i++){
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        }
        int lMax = l[0];
        int rMin = r[0];
        for(int i=1; i<m; i++){
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        }
        if(rMin-lMax<0) System.out.println("0");
        else System.out.println(rMin-lMax+1);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];

        for(int i=0; i<m; i++){
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        }
        int lMax = l[0];
        int rMin = r[0];
        for(int i=1; i<m; i++){
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        }
        if(rMin-lMax<0) System.out.println("0");
        else System.out.println(rMin-lMax+1);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];

        for(int i=0; i<m; i++){
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        }
        int lMax = l[0];
        int rMin = r[0];
        for(int i=1; i<m; i++){
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        }
        if(rMin-lMax<0) System.out.println("0");
        else System.out.println(rMin-lMax+1);
	} 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[] 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] = sc.nextInt();
          r[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        } {
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        } l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int lMax = l[0]; lMax l[0] l 0 int rMin = r[0]; rMin r[0] r 0 for(int i=1; i<m; i++){
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        } int i=1; int i=1; i 1 i<m i m i++ i++ i {
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        } {
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        } if(lMax < l[i]) lMax = l[i]; lMax < l[i] lMax l[i] l i lMax = l[i] lMax l[i] l i if(rMin > r[i]) rMin = r[i]; rMin > r[i] rMin r[i] r i rMin = r[i] rMin r[i] r i if(rMin-lMax<0) System.out.println("0");
        else System.out.println(rMin-lMax+1); rMin-lMax<0 rMin-lMax rMin lMax 0 System.out.println("0") System.out.println System.out System System.out "0" System.out.println(rMin-lMax+1) System.out.println System.out System System.out rMin-lMax+1 rMin-lMax rMin lMax 1 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[] l = new int[m];
        int[] r = new int[m];

        for(int i=0; i<m; i++){
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        }
        int lMax = l[0];
        int rMin = r[0];
        for(int i=1; i<m; i++){
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        }
        if(rMin-lMax<0) System.out.println("0");
        else System.out.println(rMin-lMax+1);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];

        for(int i=0; i<m; i++){
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        }
        int lMax = l[0];
        int rMin = r[0];
        for(int i=1; i<m; i++){
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        }
        if(rMin-lMax<0) System.out.println("0");
        else System.out.println(rMin-lMax+1);
	}
} Main
import 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[] l = new int[m];
        int[] r = new int[m];

        for(int i=0; i<m; i++){
          l[i] = sc.nextInt();
          r[i] = sc.nextInt();
        }
        int lMax = l[0];
        int rMin = r[0];
        for(int i=1; i<m; i++){
          if(lMax < l[i]) lMax = l[i];
          if(rMin > r[i]) rMin = r[i];
        }
        if(rMin-lMax<0) System.out.println("0");
        else System.out.println(rMin-lMax+1);
	}
}