import java.util.Scanner;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R));

        sc.close();
    }

    static int solve(int N, int[] L, int[] R) {
        int lower = Integer.MIN_VALUE;
        int upper = Integer.MAX_VALUE;
        for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        }

        return Math.max(0, upper - lower + 1);
    }
} import java.util.Scanner; Scanner 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();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R));

        sc.close();
    }

    static int solve(int N, int[] L, int[] R) {
        int lower = Integer.MIN_VALUE;
        int upper = Integer.MAX_VALUE;
        for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        }

        return Math.max(0, upper - lower + 1);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R));

        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R));

        sc.close();
    } 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 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] = sc.nextInt();
            R[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < M i M ++i ++i i {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        } {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        } L[i] = sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc System.out.println(solve(N, L, R)) System.out.println System.out System System.out solve(N, L, R) solve N L R sc.close() sc.close sc String[] args args static int solve(int N, int[] L, int[] R) {
        int lower = Integer.MIN_VALUE;
        int upper = Integer.MAX_VALUE;
        for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        }

        return Math.max(0, upper - lower + 1);
    } solve {
        int lower = Integer.MIN_VALUE;
        int upper = Integer.MAX_VALUE;
        for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        }

        return Math.max(0, upper - lower + 1);
    } int lower = Integer.MIN_VALUE; lower Integer.MIN_VALUE Integer Integer.MIN_VALUE int upper = Integer.MAX_VALUE; upper Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        } int i = 0; int i = 0; i 0 i < L.length i L.length L L.length ++i ++i i {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        } {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        } lower = Math.max(lower, L[i]) lower Math.max(lower, L[i]) Math.max Math lower L[i] L i upper = Math.min(upper, R[i]) upper Math.min(upper, R[i]) Math.min Math upper R[i] R i return Math.max(0, upper - lower + 1); Math.max(0, upper - lower + 1) Math.max Math 0 upper - lower + 1 upper - lower upper lower 1 int N N int[] L L int[] R R public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R));

        sc.close();
    }

    static int solve(int N, int[] L, int[] R) {
        int lower = Integer.MIN_VALUE;
        int upper = Integer.MAX_VALUE;
        for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        }

        return Math.max(0, upper - lower + 1);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R));

        sc.close();
    }

    static int solve(int N, int[] L, int[] R) {
        int lower = Integer.MIN_VALUE;
        int upper = Integer.MAX_VALUE;
        for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        }

        return Math.max(0, upper - lower + 1);
    }
} Main
import java.util.Scanner;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; ++i) {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
        }

        System.out.println(solve(N, L, R));

        sc.close();
    }

    static int solve(int N, int[] L, int[] R) {
        int lower = Integer.MIN_VALUE;
        int upper = Integer.MAX_VALUE;
        for (int i = 0; i < L.length; ++i) {
            lower = Math.max(lower, L[i]);
            upper = Math.min(upper, R[i]);
        }

        return Math.max(0, upper - lower + 1);
    }
}