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 a = sc.nextInt();      
        int b = sc.nextInt();
        
        while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        }
        if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(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 a = sc.nextInt();      
        int b = sc.nextInt();
        
        while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        }
        if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(0);
        }
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
      
        int a = sc.nextInt();      
        int b = sc.nextInt();
        
        while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        }
        if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(0);
        }
	} main {
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
      
        int a = sc.nextInt();      
        int b = sc.nextInt();
        
        while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        }
        if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(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 a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        } sc.hasNextInt() sc.hasNextInt sc {
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        } int hidari = sc.nextInt(); hidari sc.nextInt() sc.nextInt sc int migi = sc.nextInt(); migi sc.nextInt() sc.nextInt sc if(a < hidari){
              a = hidari;
            } a < hidari a hidari {
              a = hidari;
            } a = hidari a hidari if(migi < b ){
              b = migi; 
            } migi < b migi b {
              b = migi; 
            } b = migi b migi if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(0);
        } b-a+1>0 b-a+1 b-a b a 1 0 {
            System.out.println(b - a + 1);
        } System.out.println(b - a + 1) System.out.println System.out System System.out b - a + 1 b - a b a 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 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 a = sc.nextInt();      
        int b = sc.nextInt();
        
        while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        }
        if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(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 a = sc.nextInt();      
        int b = sc.nextInt();
        
        while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        }
        if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(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 a = sc.nextInt();      
        int b = sc.nextInt();
        
        while(sc.hasNextInt()){
            int hidari = sc.nextInt();
            int migi = sc.nextInt();
            if(a < hidari){
              a = hidari;
            }
            if(migi < b ){
              b = migi; 
            }
        }
        if(b-a+1>0){
            System.out.println(b - a + 1);
        }else{
            System.out.println(0);
        }
	}
}