import java.util.Scanner;

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

        int n = sc.nextInt();
        int result = n;
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();
        for(int i = 1; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        }

        result -= (min - 1);
        if(n > max){
            result -= (n - max);
        }
        if(result < 0){
            System.out.println(0);
        }else{
            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 result = n;
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();
        for(int i = 1; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        }

        result -= (min - 1);
        if(n > max){
            result -= (n - max);
        }
        if(result < 0){
            System.out.println(0);
        }else{
            System.out.println(result);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int result = n;
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();
        for(int i = 1; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        }

        result -= (min - 1);
        if(n > max){
            result -= (n - max);
        }
        if(result < 0){
            System.out.println(0);
        }else{
            System.out.println(result);
        }
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int result = n;
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();
        for(int i = 1; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        }

        result -= (min - 1);
        if(n > max){
            result -= (n - max);
        }
        if(result < 0){
            System.out.println(0);
        }else{
            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 result = n; result n int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int min = sc.nextInt(); min sc.nextInt() sc.nextInt sc int max = sc.nextInt(); max sc.nextInt() sc.nextInt sc for(int i = 1; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        } int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc if(l > min){
                min = l;
            } l > min l min {
                min = l;
            } min = l min l if(r < max){
                max = r;
            } r < max r max {
                max = r;
            } max = r max r result -= (min - 1) result (min - 1) min 1 if(n > max){
            result -= (n - max);
        } n > max n max {
            result -= (n - max);
        } result -= (n - max) result (n - max) n max if(result < 0){
            System.out.println(0);
        }else{
            System.out.println(result);
        } result < 0 result 0 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(result);
        } 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 result = n;
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();
        for(int i = 1; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        }

        result -= (min - 1);
        if(n > max){
            result -= (n - max);
        }
        if(result < 0){
            System.out.println(0);
        }else{
            System.out.println(result);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int result = n;
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();
        for(int i = 1; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        }

        result -= (min - 1);
        if(n > max){
            result -= (n - max);
        }
        if(result < 0){
            System.out.println(0);
        }else{
            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 result = n;
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();
        for(int i = 1; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l > min){
                min = l;
            }
            if(r < max){
                max = r;
            }
        }

        result -= (min - 1);
        if(n > max){
            result -= (n - max);
        }
        if(result < 0){
            System.out.println(0);
        }else{
            System.out.println(result);
        }
    }
}
