import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int m=scn.nextInt();
        int L=scn.nextInt();
        int R=scn.nextInt();
        for(int i=0;i<2*(m-1);i++){
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        }    
            
         if(L>R){
            System.out.println(0);
        }else{
            System.out.println(R-L+1);
        }
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int m=scn.nextInt();
        int L=scn.nextInt();
        int R=scn.nextInt();
        for(int i=0;i<2*(m-1);i++){
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        }    
            
         if(L>R){
            System.out.println(0);
        }else{
            System.out.println(R-L+1);
        }
    }
} Main public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int m=scn.nextInt();
        int L=scn.nextInt();
        int R=scn.nextInt();
        for(int i=0;i<2*(m-1);i++){
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        }    
            
         if(L>R){
            System.out.println(0);
        }else{
            System.out.println(R-L+1);
        }
    } main {
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int m=scn.nextInt();
        int L=scn.nextInt();
        int R=scn.nextInt();
        for(int i=0;i<2*(m-1);i++){
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        }    
            
         if(L>R){
            System.out.println(0);
        }else{
            System.out.println(R-L+1);
        }
    } Scanner scn=new Scanner(System.in); scn new Scanner(System.in) int n=scn.nextInt(); n scn.nextInt() scn.nextInt scn int m=scn.nextInt(); m scn.nextInt() scn.nextInt scn int L=scn.nextInt(); L scn.nextInt() scn.nextInt scn int R=scn.nextInt(); R scn.nextInt() scn.nextInt scn for(int i=0;i<2*(m-1);i++){
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        } int i=0; int i=0; i 0 i<2*(m-1) i 2*(m-1) 2 (m-1) m 1 i++ i++ i {
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        } {
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        } int buf=scn.nextInt(); buf scn.nextInt() scn.nextInt scn if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            } i%2==0 i%2 i 2 0 {
                if(L<buf){
                    L = buf;
                }
            } if(L<buf){
                    L = buf;
                } L<buf L buf {
                    L = buf;
                } L = buf L buf if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            } i%2==1 i%2 i 2 1 {
                if(buf<R){
                    R=buf;
                }
            } if(buf<R){
                    R=buf;
                } buf<R buf R {
                    R=buf;
                } R=buf R buf if(L>R){
            System.out.println(0);
        }else{
            System.out.println(R-L+1);
        } L>R L R {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(R-L+1);
        } System.out.println(R-L+1) System.out.println System.out System System.out R-L+1 R-L R L 1 String arg[] arg
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        int m=scn.nextInt();
        int L=scn.nextInt();
        int R=scn.nextInt();
        for(int i=0;i<2*(m-1);i++){
            int buf=scn.nextInt();
            if(i%2==0){
                if(L<buf){
                    L = buf;
                }
            }else if(i%2==1){
                if(buf<R){
                    R=buf;
                }
            }
        }    
            
         if(L>R){
            System.out.println(0);
        }else{
            System.out.println(R-L+1);
        }
    }
}
