import java.util.Scanner;

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

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            int m = sc.nextInt();

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        }
    }
} Main public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            int m = sc.nextInt();

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        }
    } main {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            int m = sc.nextInt();

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        }
    } try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            int m = sc.nextInt();

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        } {
            int n = sc.nextInt();
            int m = sc.nextInt();

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int ll = 0; ll 0 int rr = n; rr n for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            } {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            } int li = sc.nextInt(); li sc.nextInt() sc.nextInt sc int ri = sc.nextInt(); ri sc.nextInt() sc.nextInt sc if (li > ll) {
                    ll = li;
                } li > ll li ll {
                    ll = li;
                } ll = li ll li if (ri < rr) {
                    rr = ri;
                } ri < rr ri rr {
                    rr = ri;
                } rr = ri rr ri int ans = rr - ll + 1; ans rr - ll + 1 rr - ll rr ll 1 if (ans < 0) {
                ans = 0;
            } ans < 0 ans 0 {
                ans = 0;
            } ans = 0 ans 0 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) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            int m = sc.nextInt();

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            int m = sc.nextInt();

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        }
    }
} Main
import java.util.Scanner;

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

            int ll = 0;
            int rr = n;
            for (int i = 0; i < m; i++) {
                int li = sc.nextInt();
                int ri = sc.nextInt();
                if (li > ll) {
                    ll = li;
                }
                if (ri < rr) {
                    rr = ri;
                }
            }
            int ans = rr - ll + 1;
            if (ans < 0) {
                ans = 0;
            }
            System.out.println(ans);
        }
    }
}