import java.util.*;

public class Main {

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

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        }

        System.out.println(R >= L ? R - L + 1 : 0);
    }
} import java.util.*; util.* java public class Main {

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

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        }

        System.out.println(R >= L ? R - L + 1 : 0);
    }
} Main public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        }

        System.out.println(R >= L ? R - L + 1 : 0);
    } main {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        }

        System.out.println(R >= L ? R - L + 1 : 0);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc final int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int L = Integer.MIN_VALUE; L Integer.MIN_VALUE Integer Integer.MIN_VALUE int R = Integer.MAX_VALUE; R Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < M; i++) {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        } {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        } L = Math.max(L, sc.nextInt()) L Math.max(L, sc.nextInt()) Math.max Math L sc.nextInt() sc.nextInt sc R = Math.min(R, sc.nextInt()) R Math.min(R, sc.nextInt()) Math.min Math R sc.nextInt() sc.nextInt sc System.out.println(R >= L ? R - L + 1 : 0) System.out.println System.out System System.out R >= L ? R - L + 1 : 0 R >= L R L R - L + 1 R - L R L 1 0 String[] args args public class Main {

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

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        }

        System.out.println(R >= L ? R - L + 1 : 0);
    }
} public class Main {

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

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        }

        System.out.println(R >= L ? R - L + 1 : 0);
    }
} Main
import java.util.*;

public class Main {

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

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        int L = Integer.MIN_VALUE;
        int R = Integer.MAX_VALUE;
        for (int i = 0; i < M; i++) {
            L = Math.max(L, sc.nextInt());
            R = Math.min(R, sc.nextInt());
        }

        System.out.println(R >= L ? R - L + 1 : 0);
    }
}
