import java.util.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int max_l = 0;
        int min_r = Integer.MAX_VALUE;

        for(int i = 0; i<m; i++){
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        }
        int ans =0;
        for(int i=1; i<=n; i++){
            if(i>=max_l && i<=min_r){
                ans++;
            }
        }
        System.out.println(ans);
    }
}
     import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int max_l = 0;
        int min_r = Integer.MAX_VALUE;

        for(int i = 0; i<m; i++){
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        }
        int ans =0;
        for(int i=1; i<=n; i++){
            if(i>=max_l && i<=min_r){
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int max_l = 0;
        int min_r = Integer.MAX_VALUE;

        for(int i = 0; i<m; i++){
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        }
        int ans =0;
        for(int i=1; i<=n; i++){
            if(i>=max_l && i<=min_r){
                ans++;
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int max_l = 0;
        int min_r = Integer.MAX_VALUE;

        for(int i = 0; i<m; i++){
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        }
        int ans =0;
        for(int i=1; i<=n; i++){
            if(i>=max_l && i<=min_r){
                ans++;
            }
        }
        System.out.println(ans);
    } 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 max_l = 0; max_l 0 int min_r = Integer.MAX_VALUE; min_r Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0; i<m; i++){
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        } int i = 0; int i = 0; i 0 i<m i m i++ i++ i {
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        } {
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc max_l = max(l,max_l) max_l max(l,max_l) max l max_l min_r = min(r,min_r) min_r min(r,min_r) min r min_r int ans =0; ans 0 for(int i=1; i<=n; i++){
            if(i>=max_l && i<=min_r){
                ans++;
            }
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            if(i>=max_l && i<=min_r){
                ans++;
            }
        } {
            if(i>=max_l && i<=min_r){
                ans++;
            }
        } if(i>=max_l && i<=min_r){
                ans++;
            } i>=max_l && i<=min_r i>=max_l i max_l i<=min_r i min_r {
                ans++;
            } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans 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 max_l = 0;
        int min_r = Integer.MAX_VALUE;

        for(int i = 0; i<m; i++){
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        }
        int ans =0;
        for(int i=1; i<=n; i++){
            if(i>=max_l && i<=min_r){
                ans++;
            }
        }
        System.out.println(ans);
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int max_l = 0;
        int min_r = Integer.MAX_VALUE;

        for(int i = 0; i<m; i++){
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        }
        int ans =0;
        for(int i=1; i<=n; i++){
            if(i>=max_l && i<=min_r){
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int max_l = 0;
        int min_r = Integer.MAX_VALUE;

        for(int i = 0; i<m; i++){
            // if(m==1)
            int l = sc.nextInt();
            int r = sc.nextInt();
            max_l = max(l,max_l);
            min_r = min(r,min_r);
        }
        int ans =0;
        for(int i=1; i<=n; i++){
            if(i>=max_l && i<=min_r){
                ans++;
            }
        }
        System.out.println(ans);
    }
}
    