import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);
        int m = Integer.valueOf(arr01[1]);

        String arr_result[] = mylist.get(1).split(" ");

        int mindata = Integer.valueOf(arr_result[0]);
        int maxdata = Integer.valueOf(arr_result[1]);

        for (int i = 2; i < 1 + m; i++) {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        }

        System.out.println(maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0);
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);
        int m = Integer.valueOf(arr01[1]);

        String arr_result[] = mylist.get(1).split(" ");

        int mindata = Integer.valueOf(arr_result[0]);
        int maxdata = Integer.valueOf(arr_result[1]);

        for (int i = 2; i < 1 + m; i++) {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        }

        System.out.println(maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0);
    }

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

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);
        int m = Integer.valueOf(arr01[1]);

        String arr_result[] = mylist.get(1).split(" ");

        int mindata = Integer.valueOf(arr_result[0]);
        int maxdata = Integer.valueOf(arr_result[1]);

        for (int i = 2; i < 1 + m; i++) {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        }

        System.out.println(maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0);
    } main {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);
        int m = Integer.valueOf(arr01[1]);

        String arr_result[] = mylist.get(1).split(" ");

        int mindata = Integer.valueOf(arr_result[0]);
        int maxdata = Integer.valueOf(arr_result[1]);

        for (int i = 2; i < 1 + m; i++) {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        }

        System.out.println(maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0);
    } InputStreamReader is = new InputStreamReader(System.in); is new InputStreamReader(System.in) BufferedReader reader = new BufferedReader(is); reader new BufferedReader(is) List<String> mylist = new ArrayList<>(); mylist new ArrayList<>() String strinput = reader.readLine(); strinput reader.readLine() reader.readLine reader while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        } strinput != null strinput null {

            mylist.add(strinput);
            strinput = reader.readLine();

        } mylist.add(strinput) mylist.add mylist strinput strinput = reader.readLine() strinput reader.readLine() reader.readLine reader String arr01[] = mylist.get(0).split(" "); arr01 mylist.get(0).split(" ") mylist.get(0).split mylist.get(0) mylist.get mylist 0 " " int n = Integer.valueOf(arr01[0]); n Integer.valueOf(arr01[0]) Integer.valueOf Integer arr01[0] arr01 0 int m = Integer.valueOf(arr01[1]); m Integer.valueOf(arr01[1]) Integer.valueOf Integer arr01[1] arr01 1 String arr_result[] = mylist.get(1).split(" "); arr_result mylist.get(1).split(" ") mylist.get(1).split mylist.get(1) mylist.get mylist 1 " " int mindata = Integer.valueOf(arr_result[0]); mindata Integer.valueOf(arr_result[0]) Integer.valueOf Integer arr_result[0] arr_result 0 int maxdata = Integer.valueOf(arr_result[1]); maxdata Integer.valueOf(arr_result[1]) Integer.valueOf Integer arr_result[1] arr_result 1 for (int i = 2; i < 1 + m; i++) {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        } int i = 2; int i = 2; i 2 i < 1 + m i 1 + m 1 m i++ i++ i {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        } {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        } String arr02[] = mylist.get(i).split(" "); arr02 mylist.get(i).split(" ") mylist.get(i).split mylist.get(i) mylist.get mylist i " " int l = Integer.valueOf(arr02[0]); l Integer.valueOf(arr02[0]) Integer.valueOf Integer arr02[0] arr02 0 int r = Integer.valueOf(arr02[1]); r Integer.valueOf(arr02[1]) Integer.valueOf Integer arr02[1] arr02 1 if (mindata < l) {
                mindata = l;
            } mindata < l mindata l {
                mindata = l;
            } mindata = l mindata l if (maxdata > r) {
                maxdata = r;
            } maxdata > r maxdata r {
                maxdata = r;
            } maxdata = r maxdata r System.out.println(maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0) System.out.println System.out System System.out maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0 maxdata - mindata >= 0 maxdata - mindata maxdata mindata 0 maxdata - mindata + 1 maxdata - mindata maxdata mindata 1 0 String[] args args public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);
        int m = Integer.valueOf(arr01[1]);

        String arr_result[] = mylist.get(1).split(" ");

        int mindata = Integer.valueOf(arr_result[0]);
        int maxdata = Integer.valueOf(arr_result[1]);

        for (int i = 2; i < 1 + m; i++) {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        }

        System.out.println(maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0);
    }

} public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);
        int m = Integer.valueOf(arr01[1]);

        String arr_result[] = mylist.get(1).split(" ");

        int mindata = Integer.valueOf(arr_result[0]);
        int maxdata = Integer.valueOf(arr_result[1]);

        for (int i = 2; i < 1 + m; i++) {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        }

        System.out.println(maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0);
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);
        int m = Integer.valueOf(arr01[1]);

        String arr_result[] = mylist.get(1).split(" ");

        int mindata = Integer.valueOf(arr_result[0]);
        int maxdata = Integer.valueOf(arr_result[1]);

        for (int i = 2; i < 1 + m; i++) {
            String arr02[] = mylist.get(i).split(" ");
            int l = Integer.valueOf(arr02[0]);
            int r = Integer.valueOf(arr02[1]);

            if (mindata < l) {
                mindata = l;
            }
            if (maxdata > r) {
                maxdata = r;
            }

//            System.out.println(mindata + " " + maxdata);

        }

        System.out.println(maxdata - mindata >= 0 ? maxdata - mindata + 1 : 0);
    }

}
