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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int cards[] = new int[n];
        Arrays.fill(cards, 0);
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        }
        if (cards[0] == m) count++;

        System.out.println(count);
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int cards[] = new int[n];
        Arrays.fill(cards, 0);
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        }
        if (cards[0] == m) count++;

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int cards[] = new int[n];
        Arrays.fill(cards, 0);
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        }
        if (cards[0] == m) count++;

        System.out.println(count);
    } main {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int cards[] = new int[n];
        Arrays.fill(cards, 0);
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        }
        if (cards[0] == m) count++;

        System.out.println(count);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int m = in.nextInt(); m in.nextInt() in.nextInt in int cards[] = new int[n]; cards new int[n] n Arrays.fill(cards, 0) Arrays.fill Arrays cards 0 for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        } {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        } int l = in.nextInt() - 1; l in.nextInt() - 1 in.nextInt() in.nextInt in 1 int r = in.nextInt() - 1; r in.nextInt() - 1 in.nextInt() in.nextInt in 1 cards[l]++ cards[l] cards l if (r + 1 < n) {
                cards[r + 1]--;
            } r + 1 < n r + 1 r 1 n {
                cards[r + 1]--;
            } cards[r + 1]-- cards[r + 1] cards r + 1 r 1 int count = 0; count 0 for (int i = 0; i < n - 1; i++) {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        } {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        } cards[i + 1] += cards[i] cards[i + 1] cards i + 1 i 1 cards[i] cards i if (cards[i + 1] == m) count++; cards[i + 1] == m cards[i + 1] cards i + 1 i 1 m count++ count if (cards[0] == m) count++; cards[0] == m cards[0] cards 0 m count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int cards[] = new int[n];
        Arrays.fill(cards, 0);
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        }
        if (cards[0] == m) count++;

        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int cards[] = new int[n];
        Arrays.fill(cards, 0);
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        }
        if (cards[0] == m) count++;

        System.out.println(count);
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        int cards[] = new int[n];
        Arrays.fill(cards, 0);
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            cards[l]++;
            if (r + 1 < n) {
                cards[r + 1]--;
            }
        }

        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            cards[i + 1] += cards[i];
            if (cards[i + 1] == m) count++;
        }
        if (cards[0] == m) count++;

        System.out.println(count);
    }
}
