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 l = 0;
        int r = 0;

        int lmax = 0;
        int rmin = n;

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        }

        if(rmin-lmax+1 >= 0){
            System.out.println(rmin-lmax+1);

        }else{
            System.out.println(0);
        }


        sc.close();
    }
} 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 l = 0;
        int r = 0;

        int lmax = 0;
        int rmin = n;

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        }

        if(rmin-lmax+1 >= 0){
            System.out.println(rmin-lmax+1);

        }else{
            System.out.println(0);
        }


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

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

        int l = 0;
        int r = 0;

        int lmax = 0;
        int rmin = n;

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        }

        if(rmin-lmax+1 >= 0){
            System.out.println(rmin-lmax+1);

        }else{
            System.out.println(0);
        }


        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

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

        int l = 0;
        int r = 0;

        int lmax = 0;
        int rmin = n;

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        }

        if(rmin-lmax+1 >= 0){
            System.out.println(rmin-lmax+1);

        }else{
            System.out.println(0);
        }


        sc.close();
    } 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 = 0; l 0 int r = 0; r 0 int lmax = 0; lmax 0 int rmin = n; rmin n for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        } {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        } l = sc.nextInt() l sc.nextInt() sc.nextInt sc if (lmax < l) {
                lmax = l;
            } lmax < l lmax l {
                lmax = l;
            } lmax = l lmax l r = sc.nextInt() r sc.nextInt() sc.nextInt sc if (rmin > r) {
                rmin = r;
            } rmin > r rmin r {
                rmin = r;
            } rmin = r rmin r if(rmin-lmax+1 >= 0){
            System.out.println(rmin-lmax+1);

        }else{
            System.out.println(0);
        } rmin-lmax+1 >= 0 rmin-lmax+1 rmin-lmax rmin lmax 1 0 {
            System.out.println(rmin-lmax+1);

        } System.out.println(rmin-lmax+1) System.out.println System.out System System.out rmin-lmax+1 rmin-lmax rmin lmax 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 sc.close() sc.close sc 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 = 0;
        int r = 0;

        int lmax = 0;
        int rmin = n;

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        }

        if(rmin-lmax+1 >= 0){
            System.out.println(rmin-lmax+1);

        }else{
            System.out.println(0);
        }


        sc.close();
    }
} 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 = 0;
        int r = 0;

        int lmax = 0;
        int rmin = n;

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        }

        if(rmin-lmax+1 >= 0){
            System.out.println(rmin-lmax+1);

        }else{
            System.out.println(0);
        }


        sc.close();
    }
} 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 l = 0;
        int r = 0;

        int lmax = 0;
        int rmin = n;

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            if (lmax < l) {
                lmax = l;
            }

            r = sc.nextInt();
            if (rmin > r) {
                rmin = r;
            }
        }

        if(rmin-lmax+1 >= 0){
            System.out.println(rmin-lmax+1);

        }else{
            System.out.println(0);
        }


        sc.close();
    }
}
