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

    static int min(int[] l){
        int min = l[0];
        for(int i = 0; i < l.length; i++){
            if(l[i] < min)
                min = l[i];
        }
        return min;
    }
    static int max(int[] r){
        int max = r[0];
        for(int i = 0; i < r.length; i++){
            if(r[i] > max)
                max = r[i];
        }
        return max;
    }
} 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];
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }
        sc.close();
        if(min(R) - max(L) < 0)
            System.out.println(0);
        else   
            System.out.println(min(R) - max(L) + 1);
    }

    static int min(int[] l){
        int min = l[0];
        for(int i = 0; i < l.length; i++){
            if(l[i] < min)
                min = l[i];
        }
        return min;
    }
    static int max(int[] r){
        int max = r[0];
        for(int i = 0; i < r.length; i++){
            if(r[i] > max)
                max = r[i];
        }
        return max;
    }
} 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];
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }
        sc.close();
        if(min(R) - max(L) < 0)
            System.out.println(0);
        else   
            System.out.println(min(R) - max(L) + 1);
    } 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];
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }
        sc.close();
        if(min(R) - max(L) < 0)
            System.out.println(0);
        else   
            System.out.println(min(R) - max(L) + 1);
    } 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 for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        } {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        } 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 sc.close() sc.close sc if(min(R) - max(L) < 0)
            System.out.println(0);
        else   
            System.out.println(min(R) - max(L) + 1); min(R) - max(L) < 0 min(R) - max(L) min(R) min R max(L) max L 0 System.out.println(0) System.out.println System.out System System.out 0 System.out.println(min(R) - max(L) + 1) System.out.println System.out System System.out min(R) - max(L) + 1 min(R) - max(L) min(R) min R max(L) max L 1 String args[] args static int min(int[] l){
        int min = l[0];
        for(int i = 0; i < l.length; i++){
            if(l[i] < min)
                min = l[i];
        }
        return min;
    } min {
        int min = l[0];
        for(int i = 0; i < l.length; i++){
            if(l[i] < min)
                min = l[i];
        }
        return min;
    } int min = l[0]; min l[0] l 0 for(int i = 0; i < l.length; i++){
            if(l[i] < min)
                min = l[i];
        } int i = 0; int i = 0; i 0 i < l.length i l.length l l.length i++ i++ i {
            if(l[i] < min)
                min = l[i];
        } {
            if(l[i] < min)
                min = l[i];
        } if(l[i] < min)
                min = l[i]; l[i] < min l[i] l i min min = l[i] min l[i] l i return min; min int[] l l static int max(int[] r){
        int max = r[0];
        for(int i = 0; i < r.length; i++){
            if(r[i] > max)
                max = r[i];
        }
        return max;
    } max {
        int max = r[0];
        for(int i = 0; i < r.length; i++){
            if(r[i] > max)
                max = r[i];
        }
        return max;
    } int max = r[0]; max r[0] r 0 for(int i = 0; i < r.length; i++){
            if(r[i] > max)
                max = r[i];
        } int i = 0; int i = 0; i 0 i < r.length i r.length r r.length i++ i++ i {
            if(r[i] > max)
                max = r[i];
        } {
            if(r[i] > max)
                max = r[i];
        } if(r[i] > max)
                max = r[i]; r[i] > max r[i] r i max max = r[i] max r[i] r i return max; max int[] r r 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];
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }
        sc.close();
        if(min(R) - max(L) < 0)
            System.out.println(0);
        else   
            System.out.println(min(R) - max(L) + 1);
    }

    static int min(int[] l){
        int min = l[0];
        for(int i = 0; i < l.length; i++){
            if(l[i] < min)
                min = l[i];
        }
        return min;
    }
    static int max(int[] r){
        int max = r[0];
        for(int i = 0; i < r.length; i++){
            if(r[i] > max)
                max = r[i];
        }
        return max;
    }
} 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];
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }
        sc.close();
        if(min(R) - max(L) < 0)
            System.out.println(0);
        else   
            System.out.println(min(R) - max(L) + 1);
    }

    static int min(int[] l){
        int min = l[0];
        for(int i = 0; i < l.length; i++){
            if(l[i] < min)
                min = l[i];
        }
        return min;
    }
    static int max(int[] r){
        int max = r[0];
        for(int i = 0; i < r.length; i++){
            if(r[i] > max)
                max = r[i];
        }
        return max;
    }
} 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];
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }
        sc.close();
        if(min(R) - max(L) < 0)
            System.out.println(0);
        else   
            System.out.println(min(R) - max(L) + 1);
    }

    static int min(int[] l){
        int min = l[0];
        for(int i = 0; i < l.length; i++){
            if(l[i] < min)
                min = l[i];
        }
        return min;
    }
    static int max(int[] r){
        int max = r[0];
        for(int i = 0; i < r.length; i++){
            if(r[i] > max)
                max = r[i];
        }
        return max;
    }
}
