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

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n + 2];
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        }
        int cnt = 0;
        for (int i = 1; i <= n + 1; i++) {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        }
//        debug(a);
        System.out.println(cnt);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n + 2];
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        }
        int cnt = 0;
        for (int i = 1; i <= n + 1; i++) {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        }
//        debug(a);
        System.out.println(cnt);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
} Main void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n + 2];
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        }
        int cnt = 0;
        for (int i = 1; i <= n + 1; i++) {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        }
//        debug(a);
        System.out.println(cnt);
    } run {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n + 2];
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        }
        int cnt = 0;
        for (int i = 1; i <= n + 1; i++) {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        }
//        debug(a);
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int[] a = new int[n + 2]; a new int[n + 2] n + 2 n 2 for (int i = 0; i < m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        } {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        } int l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt(); r sc.nextInt() sc.nextInt sc a[l] += 1 a[l] a l 1 a[r + 1] -= 1 a[r + 1] a r + 1 r 1 1 int cnt = 0; cnt 0 for (int i = 1; i <= n + 1; i++) {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        } int i = 1; int i = 1; i 1 i <= n + 1 i n + 1 n 1 i++ i++ i {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        } {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        } a[i] += a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 if (a[i] == m) cnt++; a[i] == m a[i] a i m cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    } debug {
        System.err.println(Arrays.deepToString(os));
    } System.err.println(Arrays.deepToString(os)) System.err.println System.err System System.err Arrays.deepToString(os) Arrays.deepToString Arrays os Object...os os public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n + 2];
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        }
        int cnt = 0;
        for (int i = 1; i <= n + 1; i++) {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        }
//        debug(a);
        System.out.println(cnt);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
} public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n + 2];
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        }
        int cnt = 0;
        for (int i = 1; i <= n + 1; i++) {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        }
//        debug(a);
        System.out.println(cnt);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
} Main

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

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] a = new int[n + 2];
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt(), r = sc.nextInt();
            a[l] += 1;
            a[r + 1] -= 1;
        }
        int cnt = 0;
        for (int i = 1; i <= n + 1; i++) {
            a[i] += a[i - 1];
            if (a[i] == m) cnt++;
        }
//        debug(a);
        System.out.println(cnt);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}
