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 = new int[M];
        int[] R = new int[M];
        int ans = 0;
        L[0] = sc.nextInt();
        R[0] = sc.nextInt();
        int l = L[0];
        int r = R[0];

        for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        }
        for(int i=l; i<=r; i++){
            ans += 1;
        }
        System.out.println(ans);
    }
} 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 = new int[M];
        int[] R = new int[M];
        int ans = 0;
        L[0] = sc.nextInt();
        R[0] = sc.nextInt();
        int l = L[0];
        int r = R[0];

        for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        }
        for(int i=l; i<=r; i++){
            ans += 1;
        }
        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[] L = new int[M];
        int[] R = new int[M];
        int ans = 0;
        L[0] = sc.nextInt();
        R[0] = sc.nextInt();
        int l = L[0];
        int r = R[0];

        for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        }
        for(int i=l; i<=r; i++){
            ans += 1;
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int ans = 0;
        L[0] = sc.nextInt();
        R[0] = sc.nextInt();
        int l = L[0];
        int r = R[0];

        for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        }
        for(int i=l; i<=r; i++){
            ans += 1;
        }
        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[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M int ans = 0; ans 0 L[0] = sc.nextInt() L[0] L 0 sc.nextInt() sc.nextInt sc R[0] = sc.nextInt() R[0] R 0 sc.nextInt() sc.nextInt sc int l = L[0]; l L[0] L 0 int r = R[0]; r R[0] R 0 for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        } int i=1; int i=1; i 1 i<M i M i++ i++ i {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        } {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        } L[i] = sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc if(L[i]>l){
                l = L[i];
            } L[i]>l L[i] L i l {
                l = L[i];
            } l = L[i] l L[i] L i if(R[i]<r){
                r = R[i];
            } R[i]<r R[i] R i r {
                r = R[i];
            } r = R[i] r R[i] R i for(int i=l; i<=r; i++){
            ans += 1;
        } int i=l; int i=l; i l i<=r i r i++ i++ i {
            ans += 1;
        } {
            ans += 1;
        } ans += 1 ans 1 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[] L = new int[M];
        int[] R = new int[M];
        int ans = 0;
        L[0] = sc.nextInt();
        R[0] = sc.nextInt();
        int l = L[0];
        int r = R[0];

        for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        }
        for(int i=l; i<=r; i++){
            ans += 1;
        }
        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[] L = new int[M];
        int[] R = new int[M];
        int ans = 0;
        L[0] = sc.nextInt();
        R[0] = sc.nextInt();
        int l = L[0];
        int r = R[0];

        for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        }
        for(int i=l; i<=r; i++){
            ans += 1;
        }
        System.out.println(ans);
    }
} 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 = new int[M];
        int[] R = new int[M];
        int ans = 0;
        L[0] = sc.nextInt();
        R[0] = sc.nextInt();
        int l = L[0];
        int r = R[0];

        for(int i=1; i<M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            if(L[i]>l){
                l = L[i];
            }
            if(R[i]<r){
                r = R[i];
            }
        }
        for(int i=l; i<=r; i++){
            ans += 1;
        }
        System.out.println(ans);
    }
}