import java.util.*;

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

        boolean[] cardStatus = new boolean[N];
        Arrays.fill(cardStatus, true);

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        }
        sc.close();

        int cnt = 0;
        for (int i = 0; i < cardStatus.length; i++) {
            if (cardStatus[i]) {
                cnt++;
            }
        }
        System.out.println(cnt);

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        boolean[] cardStatus = new boolean[N];
        Arrays.fill(cardStatus, true);

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        }
        sc.close();

        int cnt = 0;
        for (int i = 0; i < cardStatus.length; i++) {
            if (cardStatus[i]) {
                cnt++;
            }
        }
        System.out.println(cnt);

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        boolean[] cardStatus = new boolean[N];
        Arrays.fill(cardStatus, true);

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        }
        sc.close();

        int cnt = 0;
        for (int i = 0; i < cardStatus.length; i++) {
            if (cardStatus[i]) {
                cnt++;
            }
        }
        System.out.println(cnt);

    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        boolean[] cardStatus = new boolean[N];
        Arrays.fill(cardStatus, true);

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        }
        sc.close();

        int cnt = 0;
        for (int i = 0; i < cardStatus.length; i++) {
            if (cardStatus[i]) {
                cnt++;
            }
        }
        System.out.println(cnt);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc boolean[] cardStatus = new boolean[N]; cardStatus new boolean[N] N Arrays.fill(cardStatus, true) Arrays.fill Arrays cardStatus true for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        } {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        } int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            } int j = 0; int j = 0; j 0 j < L - 1 j L - 1 L 1 j++ j++ j {
                cardStatus[j] = false;
            } {
                cardStatus[j] = false;
            } cardStatus[j] = false cardStatus[j] cardStatus j false for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            } int k = R; int k = R; k R k < cardStatus.length k cardStatus.length cardStatus cardStatus.length k++ k++ k {
                cardStatus[k] = false;
            } {
                cardStatus[k] = false;
            } cardStatus[k] = false cardStatus[k] cardStatus k false sc.close() sc.close sc int cnt = 0; cnt 0 for (int i = 0; i < cardStatus.length; i++) {
            if (cardStatus[i]) {
                cnt++;
            }
        } int i = 0; int i = 0; i 0 i < cardStatus.length i cardStatus.length cardStatus cardStatus.length i++ i++ i {
            if (cardStatus[i]) {
                cnt++;
            }
        } {
            if (cardStatus[i]) {
                cnt++;
            }
        } if (cardStatus[i]) {
                cnt++;
            } cardStatus[i] cardStatus i {
                cnt++;
            } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        boolean[] cardStatus = new boolean[N];
        Arrays.fill(cardStatus, true);

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        }
        sc.close();

        int cnt = 0;
        for (int i = 0; i < cardStatus.length; i++) {
            if (cardStatus[i]) {
                cnt++;
            }
        }
        System.out.println(cnt);

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        boolean[] cardStatus = new boolean[N];
        Arrays.fill(cardStatus, true);

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        }
        sc.close();

        int cnt = 0;
        for (int i = 0; i < cardStatus.length; i++) {
            if (cardStatus[i]) {
                cnt++;
            }
        }
        System.out.println(cnt);

    }
} Main
import java.util.*;

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

        boolean[] cardStatus = new boolean[N];
        Arrays.fill(cardStatus, true);

        for (int i = 0; i < M; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            for (int j = 0; j < L - 1; j++) {
                cardStatus[j] = false;
            }

            for (int k = R; k < cardStatus.length; k++) {
                cardStatus[k] = false;
            }
        }
        sc.close();

        int cnt = 0;
        for (int i = 0; i < cardStatus.length; i++) {
            if (cardStatus[i]) {
                cnt++;
            }
        }
        System.out.println(cnt);

    }
}
