import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] in = sc.nextLine().split(" ");
        int N = Integer.parseInt(in[0]);
        int M = Integer.parseInt(in[1]);

        // いもす法で解いてみる
        int[] imos = new int[N + 1];
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        }

        // 累積和
        for (int i = 0; i < N; i++) {
            imos[i + 1] += imos[i];
        }

        // 答え
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (imos[i] == M) {
                ans++;
            }
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] in = sc.nextLine().split(" ");
        int N = Integer.parseInt(in[0]);
        int M = Integer.parseInt(in[1]);

        // いもす法で解いてみる
        int[] imos = new int[N + 1];
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        }

        // 累積和
        for (int i = 0; i < N; i++) {
            imos[i + 1] += imos[i];
        }

        // 答え
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (imos[i] == M) {
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] in = sc.nextLine().split(" ");
        int N = Integer.parseInt(in[0]);
        int M = Integer.parseInt(in[1]);

        // いもす法で解いてみる
        int[] imos = new int[N + 1];
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        }

        // 累積和
        for (int i = 0; i < N; i++) {
            imos[i + 1] += imos[i];
        }

        // 答え
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (imos[i] == M) {
                ans++;
            }
        }
        System.out.println(ans);
    } main {

        Scanner sc = new Scanner(System.in);
        String[] in = sc.nextLine().split(" ");
        int N = Integer.parseInt(in[0]);
        int M = Integer.parseInt(in[1]);

        // いもす法で解いてみる
        int[] imos = new int[N + 1];
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        }

        // 累積和
        for (int i = 0; i < N; i++) {
            imos[i + 1] += imos[i];
        }

        // 答え
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (imos[i] == M) {
                ans++;
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] in = sc.nextLine().split(" "); in sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int N = Integer.parseInt(in[0]); N Integer.parseInt(in[0]) Integer.parseInt Integer in[0] in 0 int M = Integer.parseInt(in[1]); M Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 int[] imos = new int[N + 1]; imos new int[N + 1] N + 1 N 1 for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        } {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        } int start = Integer.parseInt(sc.next()); start Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int end = Integer.parseInt(sc.next()); end Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc imos[start - 1]++ imos[start - 1] imos start - 1 start 1 imos[end]-- imos[end] imos end for (int i = 0; i < N; i++) {
            imos[i + 1] += imos[i];
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            imos[i + 1] += imos[i];
        } {
            imos[i + 1] += imos[i];
        } imos[i + 1] += imos[i] imos[i + 1] imos i + 1 i 1 imos[i] imos i int ans = 0; ans 0 for (int i = 0; i < N; i++) {
            if (imos[i] == M) {
                ans++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            if (imos[i] == M) {
                ans++;
            }
        } {
            if (imos[i] == M) {
                ans++;
            }
        } if (imos[i] == M) {
                ans++;
            } imos[i] == M imos[i] imos i M {
                ans++;
            } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] in = sc.nextLine().split(" ");
        int N = Integer.parseInt(in[0]);
        int M = Integer.parseInt(in[1]);

        // いもす法で解いてみる
        int[] imos = new int[N + 1];
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        }

        // 累積和
        for (int i = 0; i < N; i++) {
            imos[i + 1] += imos[i];
        }

        // 答え
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (imos[i] == M) {
                ans++;
            }
        }
        System.out.println(ans);
    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] in = sc.nextLine().split(" ");
        int N = Integer.parseInt(in[0]);
        int M = Integer.parseInt(in[1]);

        // いもす法で解いてみる
        int[] imos = new int[N + 1];
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        }

        // 累積和
        for (int i = 0; i < N; i++) {
            imos[i + 1] += imos[i];
        }

        // 答え
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (imos[i] == M) {
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] in = sc.nextLine().split(" ");
        int N = Integer.parseInt(in[0]);
        int M = Integer.parseInt(in[1]);

        // いもす法で解いてみる
        int[] imos = new int[N + 1];
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            imos[start - 1]++;
            imos[end]--;
        }

        // 累積和
        for (int i = 0; i < N; i++) {
            imos[i + 1] += imos[i];
        }

        // 答え
        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (imos[i] == M) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}
