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 = 1;
        int R = n;
        for(int i=0;i<m;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            }
	    System.out.println(Math.max(R-L+1,0));
  }
} 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 = 1;
        int R = n;
        for(int i=0;i<m;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            }
	    System.out.println(Math.max(R-L+1,0));
  }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
		int m = sc.nextInt();
        int L = 1;
        int R = n;
        for(int i=0;i<m;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            }
	    System.out.println(Math.max(R-L+1,0));
  } main {
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
		int m = sc.nextInt();
        int L = 1;
        int R = n;
        for(int i=0;i<m;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            }
	    System.out.println(Math.max(R-L+1,0));
  } 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 = 1; L 1 int R = n; R n for(int i=0;i<m;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            } int i=0; int i=0; i 0 i<m i m i++ i++ i {int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            } {int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc L=Math.max(L,l) L Math.max(L,l) Math.max Math L l R=Math.min(R,r) R Math.min(R,r) Math.min Math R r System.out.println(Math.max(R-L+1,0)) System.out.println System.out System System.out Math.max(R-L+1,0) Math.max Math R-L+1 R-L R L 1 0 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 = 1;
        int R = n;
        for(int i=0;i<m;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            }
	    System.out.println(Math.max(R-L+1,0));
  }
} 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 = 1;
        int R = n;
        for(int i=0;i<m;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            }
	    System.out.println(Math.max(R-L+1,0));
  }
} 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 = 1;
        int R = n;
        for(int i=0;i<m;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             L=Math.max(L,l);
                             R=Math.min(R,r);
                            }
	    System.out.println(Math.max(R-L+1,0));
  }
}
