import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N,M,count;
        int L;
        int R;
        int A,B;

        count = 0;
        N = sc.nextInt();
        M = sc.nextInt();
        L = sc.nextInt();
        R = sc.nextInt();
        
        for(int i = 0; i < M - 1; i++) {
           A = sc.nextInt();
           B = sc.nextInt();
           if(L < A) {
              L = A;
           }
           if(R > B) {
              R = B;
           }   
        }
        if(R >= L) {
          count = R - L + 1;
        }else { 
          count = 0;
        }
        
      

        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N,M,count;
        int L;
        int R;
        int A,B;

        count = 0;
        N = sc.nextInt();
        M = sc.nextInt();
        L = sc.nextInt();
        R = sc.nextInt();
        
        for(int i = 0; i < M - 1; i++) {
           A = sc.nextInt();
           B = sc.nextInt();
           if(L < A) {
              L = A;
           }
           if(R > B) {
              R = B;
           }   
        }
        if(R >= L) {
          count = R - L + 1;
        }else { 
          count = 0;
        }
        
      

        System.out.println(count);
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N,M,count;
        int L;
        int R;
        int A,B;

        count = 0;
        N = sc.nextInt();
        M = sc.nextInt();
        L = sc.nextInt();
        R = sc.nextInt();
        
        for(int i = 0; i < M - 1; i++) {
           A = sc.nextInt();
           B = sc.nextInt();
           if(L < A) {
              L = A;
           }
           if(R > B) {
              R = B;
           }   
        }
        if(R >= L) {
          count = R - L + 1;
        }else { 
          count = 0;
        }
        
      

        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int N,M,count;
        int L;
        int R;
        int A,B;

        count = 0;
        N = sc.nextInt();
        M = sc.nextInt();
        L = sc.nextInt();
        R = sc.nextInt();
        
        for(int i = 0; i < M - 1; i++) {
           A = sc.nextInt();
           B = sc.nextInt();
           if(L < A) {
              L = A;
           }
           if(R > B) {
              R = B;
           }   
        }
        if(R >= L) {
          count = R - L + 1;
        }else { 
          count = 0;
        }
        
      

        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N N M M count; count int L; L int R; R int A A B; B count = 0 count 0 N = sc.nextInt() N sc.nextInt() sc.nextInt sc M = sc.nextInt() M sc.nextInt() sc.nextInt sc L = sc.nextInt() L sc.nextInt() sc.nextInt sc R = sc.nextInt() R sc.nextInt() sc.nextInt sc for(int i = 0; i < M - 1; i++) {
           A = sc.nextInt();
           B = sc.nextInt();
           if(L < A) {
              L = A;
           }
           if(R > B) {
              R = B;
           }   
        } int i = 0; int i = 0; i 0 i < M - 1 i M - 1 M 1 i++ i++ i {
           A = sc.nextInt();
           B = sc.nextInt();
           if(L < A) {
              L = A;
           }
           if(R > B) {
              R = B;
           }   
        } {
           A = sc.nextInt();
           B = sc.nextInt();
           if(L < A) {
              L = A;
           }
           if(R > B) {
              R = B;
           }   
        } A = sc.nextInt() A sc.nextInt() sc.nextInt sc B = sc.nextInt() B sc.nextInt() sc.nextInt sc if(L < A) {
              L = A;
           } L < A L A {
              L = A;
           } L = A L A if(R > B) {
              R = B;
           } R > B R B {
              R = B;
           } R = B R B if(R >= L) {
          count = R - L + 1;
        }else { 
          count = 0;
        } R >= L R L {
          count = R - L + 1;
        } count = R - L + 1 count R - L + 1 R - L R L 1 { 
          count = 0;
        } count = 0 count 0 System.out.println(count) System.out.println System.out System System.out count String args[] args
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N,M,count;
        int L;
        int R;
        int A,B;

        count = 0;
        N = sc.nextInt();
        M = sc.nextInt();
        L = sc.nextInt();
        R = sc.nextInt();
        
        for(int i = 0; i < M - 1; i++) {
           A = sc.nextInt();
           B = sc.nextInt();
           if(L < A) {
              L = A;
           }
           if(R > B) {
              R = B;
           }   
        }
        if(R >= L) {
          count = R - L + 1;
        }else { 
          count = 0;
        }
        
      

        System.out.println(count);
    }
}