import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int cardNum = sc.nextInt(); // カード N 枚 ：(0 ~ N-1)
        int gateNum = sc.nextInt(); // ゲート M 個 ：(0 ~ M-1)
        int[] left = new int[gateNum];
        int[] right = new int[gateNum];
        for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int curStart = 1;
        int curEnd = cardNum;
        for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        }
        int ans = curEnd - curStart + 1;
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int cardNum = sc.nextInt(); // カード N 枚 ：(0 ~ N-1)
        int gateNum = sc.nextInt(); // ゲート M 個 ：(0 ~ M-1)
        int[] left = new int[gateNum];
        int[] right = new int[gateNum];
        for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int curStart = 1;
        int curEnd = cardNum;
        for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        }
        int ans = curEnd - curStart + 1;
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} Main void solve() {
        Scanner sc = new Scanner(System.in);
        int cardNum = sc.nextInt(); // カード N 枚 ：(0 ~ N-1)
        int gateNum = sc.nextInt(); // ゲート M 個 ：(0 ~ M-1)
        int[] left = new int[gateNum];
        int[] right = new int[gateNum];
        for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int curStart = 1;
        int curEnd = cardNum;
        for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        }
        int ans = curEnd - curStart + 1;
        System.out.print(ans);
    } solve {
        Scanner sc = new Scanner(System.in);
        int cardNum = sc.nextInt(); // カード N 枚 ：(0 ~ N-1)
        int gateNum = sc.nextInt(); // ゲート M 個 ：(0 ~ M-1)
        int[] left = new int[gateNum];
        int[] right = new int[gateNum];
        for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int curStart = 1;
        int curEnd = cardNum;
        for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        }
        int ans = curEnd - curStart + 1;
        System.out.print(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int cardNum = sc.nextInt(); cardNum sc.nextInt() sc.nextInt sc int gateNum = sc.nextInt(); gateNum sc.nextInt() sc.nextInt sc int[] left = new int[gateNum]; left new int[gateNum] gateNum int[] right = new int[gateNum]; right new int[gateNum] gateNum for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < gateNum i gateNum i++ i++ i {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        } {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        } left[i] = sc.nextInt() left[i] left i sc.nextInt() sc.nextInt sc right[i] = sc.nextInt() right[i] right i sc.nextInt() sc.nextInt sc int curStart = 1; curStart 1 int curEnd = cardNum; curEnd cardNum for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        } int i = 0; int i = 0; i 0 i < gateNum i gateNum i++ i++ i {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        } {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        } int start = left[i]; start left[i] left i int end = right[i]; end right[i] right i if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            } end < curStart || curEnd < start end < curStart end curStart curEnd < start curEnd start {
                System.out.print(0);
                return;
            } System.out.print(0) System.out.print System.out System System.out 0 return; {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            } if (curStart < start) {
                    curStart = start;
                } curStart < start curStart start {
                    curStart = start;
                } curStart = start curStart start if (end < curEnd) {
                    curEnd = end;
                } end < curEnd end curEnd {
                    curEnd = end;
                } curEnd = end curEnd end int ans = curEnd - curStart + 1; ans curEnd - curStart + 1 curEnd - curStart curEnd curStart 1 System.out.print(ans) System.out.print System.out System System.out ans // Main
    public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int cardNum = sc.nextInt(); // カード N 枚 ：(0 ~ N-1)
        int gateNum = sc.nextInt(); // ゲート M 個 ：(0 ~ M-1)
        int[] left = new int[gateNum];
        int[] right = new int[gateNum];
        for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int curStart = 1;
        int curEnd = cardNum;
        for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        }
        int ans = curEnd - curStart + 1;
        System.out.print(ans);
    }

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int cardNum = sc.nextInt(); // カード N 枚 ：(0 ~ N-1)
        int gateNum = sc.nextInt(); // ゲート M 個 ：(0 ~ M-1)
        int[] left = new int[gateNum];
        int[] right = new int[gateNum];
        for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int curStart = 1;
        int curEnd = cardNum;
        for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        }
        int ans = curEnd - curStart + 1;
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int cardNum = sc.nextInt(); // カード N 枚 ：(0 ~ N-1)
        int gateNum = sc.nextInt(); // ゲート M 個 ：(0 ~ M-1)
        int[] left = new int[gateNum];
        int[] right = new int[gateNum];
        for (int i = 0; i < gateNum; i++) {
            left[i] = sc.nextInt();
            right[i] = sc.nextInt();
        }

        int curStart = 1;
        int curEnd = cardNum;
        for (int i = 0; i < gateNum; i++) {
            int start = left[i];
            int end = right[i];

            // 共通部分なし
            if(end < curStart || curEnd < start) {
                System.out.print(0);
                return;
            }
            else {
                if (curStart < start) {
                    curStart = start;
                }
                if (end < curEnd) {
                    curEnd = end;
                }
            }
        }
        int ans = curEnd - curStart + 1;
        System.out.print(ans);
    }

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