import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) C solver = new C(); solver new C() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        }

    } C public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        } solve {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        } int n = Integer.parseInt(in.next()); n Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int m = Integer.parseInt(in.next()); m Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int lr[][] = new int[m][2]; lr new int[m][2] m 2 int min = 1; min 1 int max = n; max n for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            } {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            } lr[i][0] = Integer.parseInt(in.next()) lr[i][0] lr[i] lr i 0 Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in lr[i][1] = Integer.parseInt(in.next()) lr[i][1] lr[i] lr i 1 Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in min = Math.max(min, lr[i][0]) min Math.max(min, lr[i][0]) Math.max Math min lr[i][0] lr[i] lr i 0 max = Math.min(max, lr[i][1]) max Math.min(max, lr[i][1]) Math.min Math max lr[i][1] lr[i] lr i 1 out.println(Math.max(0, max - min + 1)) out.println out Math.max(0, max - min + 1) Math.max Math 0 max - min + 1 max - min max min 1 int testNumber testNumber Scanner in in PrintWriter out out public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        }

    }
}

