import java.util.*;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        }
        scanner.close();

        // index start
        int idxStart = 1;

        // index end
        int idxEnd = N;

        for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        }

        // result count
        int result = idxEnd - idxStart;
        if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        }

        System.out.println(result);

//        System.out.println(System.currentTimeMillis() - startTime);
    }


} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        }
        scanner.close();

        // index start
        int idxStart = 1;

        // index end
        int idxEnd = N;

        for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        }

        // result count
        int result = idxEnd - idxStart;
        if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        }

        System.out.println(result);

//        System.out.println(System.currentTimeMillis() - startTime);
    }


} Main public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        }
        scanner.close();

        // index start
        int idxStart = 1;

        // index end
        int idxEnd = N;

        for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        }

        // result count
        int result = idxEnd - idxStart;
        if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        }

        System.out.println(result);

//        System.out.println(System.currentTimeMillis() - startTime);
    } main {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        }
        scanner.close();

        // index start
        int idxStart = 1;

        // index end
        int idxEnd = N;

        for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        }

        // result count
        int result = idxEnd - idxStart;
        if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        }

        System.out.println(result);

//        System.out.println(System.currentTimeMillis() - startTime);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int M = scanner.nextInt(); M scanner.nextInt() scanner.nextInt scanner int[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        } {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        } L[i] = scanner.nextInt() L[i] L i scanner.nextInt() scanner.nextInt scanner R[i] = scanner.nextInt() R[i] R i scanner.nextInt() scanner.nextInt scanner scanner.close() scanner.close scanner int idxStart = 1; idxStart 1 int idxEnd = N; idxEnd N for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        } {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        } int l = L[i]; l L[i] L i int r = R[i]; r R[i] R i if (idxStart < l) {
                idxStart = l;
            } idxStart < l idxStart l {
                idxStart = l;
            } idxStart = l idxStart l if (idxEnd > r) {
                idxEnd = r;
            } idxEnd > r idxEnd r {
                idxEnd = r;
            } idxEnd = r idxEnd r int result = idxEnd - idxStart; result idxEnd - idxStart idxEnd idxStart if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        } result == 0 result 0 {
            result = 1;
        } result = 1 result 1 if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        } result < 0 result 0 {
            result = 0;
        } result = 0 result 0 {
            result = result + 1;
        } result = result + 1 result result + 1 result 1 System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        }
        scanner.close();

        // index start
        int idxStart = 1;

        // index end
        int idxEnd = N;

        for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        }

        // result count
        int result = idxEnd - idxStart;
        if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        }

        System.out.println(result);

//        System.out.println(System.currentTimeMillis() - startTime);
    }


} public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        }
        scanner.close();

        // index start
        int idxStart = 1;

        // index end
        int idxEnd = N;

        for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        }

        // result count
        int result = idxEnd - idxStart;
        if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        }

        System.out.println(result);

//        System.out.println(System.currentTimeMillis() - startTime);
    }


} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scanner.nextInt();
            R[i] = scanner.nextInt();
        }
        scanner.close();

        // index start
        int idxStart = 1;

        // index end
        int idxEnd = N;

        for (int i = 0; i < M; i++) {
            int l = L[i];
            int r = R[i];
            if (idxStart < l) {
                idxStart = l;
            }
            if (idxEnd > r) {
                idxEnd = r;
            }
        }

        // result count
        int result = idxEnd - idxStart;
        if (result == 0) {
            result = 1;
        } else if (result < 0) {
            result = 0;
        } else {
            result = result + 1;
        }

        System.out.println(result);

//        System.out.println(System.currentTimeMillis() - startTime);
    }


}
