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();

        int min = sc.nextInt();
        int max = sc.nextInt();

        for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        }

        System.out.println(Math.max((Math.min(n, max) - min + 1), 0));

        sc.close();

    }

} 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();

        int min = sc.nextInt();
        int max = sc.nextInt();

        for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        }

        System.out.println(Math.max((Math.min(n, max) - min + 1), 0));

        sc.close();

    }

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();

        for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        }

        System.out.println(Math.max((Math.min(n, max) - min + 1), 0));

        sc.close();

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();

        for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        }

        System.out.println(Math.max((Math.min(n, max) - min + 1), 0));

        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 min = sc.nextInt(); min sc.nextInt() sc.nextInt sc int max = sc.nextInt(); max sc.nextInt() sc.nextInt sc for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        } int i = 0; int i = 0; i 0 i < m - 1 i m - 1 m 1 i++ i++ i {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        } {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        } int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc if (min < a) {
                min = a;
            } min < a min a {
                min = a;
            } min = a min a int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc if (b < max) {
                max = b;
            } b < max b max {
                max = b;
            } max = b max b System.out.println(Math.max((Math.min(n, max) - min + 1), 0)) System.out.println System.out System System.out Math.max((Math.min(n, max) - min + 1), 0) Math.max Math (Math.min(n, max) - min + 1) Math.min(n, max) - min Math.min(n, max) Math.min Math n max min 1 0 sc.close() sc.close sc 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();

        int min = sc.nextInt();
        int max = sc.nextInt();

        for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        }

        System.out.println(Math.max((Math.min(n, max) - min + 1), 0));

        sc.close();

    }

} public class Main {

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = sc.nextInt();
        int max = sc.nextInt();

        for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        }

        System.out.println(Math.max((Math.min(n, max) - min + 1), 0));

        sc.close();

    }

} 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();

        int min = sc.nextInt();
        int max = sc.nextInt();

        for (int i = 0; i < m - 1; i++) {
            int a = sc.nextInt();
            if (min < a) {
                min = a;
            }
            int b = sc.nextInt();
            if (b < max) {
                max = b;
            }
        }

        System.out.println(Math.max((Math.min(n, max) - min + 1), 0));

        sc.close();

    }

}