import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int left=0, right=2147483647;

        int l, r;
        for (int i=0; i<M; i++){
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        }
        sc.close();

        int result=0;
        if(left <= right){
            result = right - left + 1;
        }
            
        System .out.println(result);

    }

} import java.util.Scanner; Scanner 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 left=0, right=2147483647;

        int l, r;
        for (int i=0; i<M; i++){
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        }
        sc.close();

        int result=0;
        if(left <= right){
            result = right - left + 1;
        }
            
        System .out.println(result);

    }

} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int left=0, right=2147483647;

        int l, r;
        for (int i=0; i<M; i++){
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        }
        sc.close();

        int result=0;
        if(left <= right){
            result = right - left + 1;
        }
            
        System .out.println(result);

    } main {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int left=0, right=2147483647;

        int l, r;
        for (int i=0; i<M; i++){
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        }
        sc.close();

        int result=0;
        if(left <= right){
            result = right - left + 1;
        }
            
        System .out.println(result);

    } 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 left=0 left 0 right=2147483647; right 2147483647 int l l r; r for (int i=0; i<M; i++){
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        } int i=0; int i=0; i 0 i<M i M i++ i++ i {
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        } {
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        } l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt() r sc.nextInt() sc.nextInt sc if (l > left){
                left = l;
            } l > left l left {
                left = l;
            } left = l left l if (r < right){
                right = r;
            } r < right r right {
                right = r;
            } right = r right r sc.close() sc.close sc int result=0; result 0 if(left <= right){
            result = right - left + 1;
        } left <= right left right {
            result = right - left + 1;
        } result = right - left + 1 result right - left + 1 right - left right left 1 System .out.println(result) System .out.println System .out System System .out result 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 left=0, right=2147483647;

        int l, r;
        for (int i=0; i<M; i++){
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        }
        sc.close();

        int result=0;
        if(left <= right){
            result = right - left + 1;
        }
            
        System .out.println(result);

    }

} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int left=0, right=2147483647;

        int l, r;
        for (int i=0; i<M; i++){
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        }
        sc.close();

        int result=0;
        if(left <= right){
            result = right - left + 1;
        }
            
        System .out.println(result);

    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int left=0, right=2147483647;

        int l, r;
        for (int i=0; i<M; i++){
            l = sc.nextInt();
            r = sc.nextInt();
            if (l > left){
                left = l;
            }
            if (r < right){
                right = r;
            }
        }
        sc.close();

        int result=0;
        if(left <= right){
            result = right - left + 1;
        }
            
        System .out.println(result);

    }

}