import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer m = Integer.parseInt(sc.next());
        Integer[] l = new Integer[m];
        Integer[] r = new Integer[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        Arrays.sort(r);

        int min = l[m - 1];
        int max = r[0];

        int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n);

        // 出力
        System.out.println(result);
        sc.close();
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer m = Integer.parseInt(sc.next());
        Integer[] l = new Integer[m];
        Integer[] r = new Integer[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        Arrays.sort(r);

        int min = l[m - 1];
        int max = r[0];

        int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n);

        // 出力
        System.out.println(result);
        sc.close();
    }
} Main public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer m = Integer.parseInt(sc.next());
        Integer[] l = new Integer[m];
        Integer[] r = new Integer[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        Arrays.sort(r);

        int min = l[m - 1];
        int max = r[0];

        int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n);

        // 出力
        System.out.println(result);
        sc.close();
    } main {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer m = Integer.parseInt(sc.next());
        Integer[] l = new Integer[m];
        Integer[] r = new Integer[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        Arrays.sort(r);

        int min = l[m - 1];
        int max = r[0];

        int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n);

        // 出力
        System.out.println(result);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Integer n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Integer m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Integer[] l = new Integer[m]; l new Integer[m] m Integer[] r = new Integer[m]; r new Integer[m] m for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } l[i] = Integer.parseInt(sc.next()) l[i] l i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r[i] = Integer.parseInt(sc.next()) r[i] r i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Arrays.sort(l) Arrays.sort Arrays l Arrays.sort(r) Arrays.sort Arrays r int min = l[m - 1]; min l[m - 1] l m - 1 m 1 int max = r[0]; max r[0] r 0 int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n); result max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n) max - min + 1 < 0 max - min + 1 max - min max min 1 0 0 Math.min(max - min + 1, n) Math.min Math max - min + 1 max - min max min 1 n System.out.println(result) System.out.println System.out System System.out result sc.close() sc.close sc String args[] args public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer m = Integer.parseInt(sc.next());
        Integer[] l = new Integer[m];
        Integer[] r = new Integer[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        Arrays.sort(r);

        int min = l[m - 1];
        int max = r[0];

        int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n);

        // 出力
        System.out.println(result);
        sc.close();
    }
} public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer m = Integer.parseInt(sc.next());
        Integer[] l = new Integer[m];
        Integer[] r = new Integer[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        Arrays.sort(r);

        int min = l[m - 1];
        int max = r[0];

        int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n);

        // 出力
        System.out.println(result);
        sc.close();
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.parseInt(sc.next());
        Integer m = Integer.parseInt(sc.next());
        Integer[] l = new Integer[m];
        Integer[] r = new Integer[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(l);
        Arrays.sort(r);

        int min = l[m - 1];
        int max = r[0];

        int result = max - min + 1 < 0 ? 0 : Math.min(max - min + 1, n);

        // 出力
        System.out.println(result);
        sc.close();
    }
}