
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        List<Integer> leftList = new ArrayList<>();
        List<Integer> rightList = new ArrayList<>();
        for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        }

        int left = Collections.max(leftList);
        int right = Collections.min(rightList);

        int result = Math.min(right, N) - Math.max(left, 1) + 1;
        if (result < 0) {
            result = 0;
        }

        System.out.println(result);
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        List<Integer> leftList = new ArrayList<>();
        List<Integer> rightList = new ArrayList<>();
        for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        }

        int left = Collections.max(leftList);
        int right = Collections.min(rightList);

        int result = Math.min(right, N) - Math.max(left, 1) + 1;
        if (result < 0) {
            result = 0;
        }

        System.out.println(result);
    }
} Main public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        List<Integer> leftList = new ArrayList<>();
        List<Integer> rightList = new ArrayList<>();
        for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        }

        int left = Collections.max(leftList);
        int right = Collections.min(rightList);

        int result = Math.min(right, N) - Math.max(left, 1) + 1;
        if (result < 0) {
            result = 0;
        }

        System.out.println(result);
    } main {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        List<Integer> leftList = new ArrayList<>();
        List<Integer> rightList = new ArrayList<>();
        for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        }

        int left = Collections.max(leftList);
        int right = Collections.min(rightList);

        int result = Math.min(right, N) - Math.max(left, 1) + 1;
        if (result < 0) {
            result = 0;
        }

        System.out.println(result);
    } 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 List<Integer> leftList = new ArrayList<>(); leftList new ArrayList<>() List<Integer> rightList = new ArrayList<>(); rightList new ArrayList<>() for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        } int i=0; int i=0; i 0 i < M i M i++ i++ i {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        } {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        } leftList.add(scanner.nextInt()) leftList.add leftList scanner.nextInt() scanner.nextInt scanner rightList.add(scanner.nextInt()) rightList.add rightList scanner.nextInt() scanner.nextInt scanner int left = Collections.max(leftList); left Collections.max(leftList) Collections.max Collections leftList int right = Collections.min(rightList); right Collections.min(rightList) Collections.min Collections rightList int result = Math.min(right, N) - Math.max(left, 1) + 1; result Math.min(right, N) - Math.max(left, 1) + 1 Math.min(right, N) - Math.max(left, 1) Math.min(right, N) Math.min Math right N Math.max(left, 1) Math.max Math left 1 1 if (result < 0) {
            result = 0;
        } result < 0 result 0 {
            result = 0;
        } result = 0 result 0 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) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        List<Integer> leftList = new ArrayList<>();
        List<Integer> rightList = new ArrayList<>();
        for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        }

        int left = Collections.max(leftList);
        int right = Collections.min(rightList);

        int result = Math.min(right, N) - Math.max(left, 1) + 1;
        if (result < 0) {
            result = 0;
        }

        System.out.println(result);
    }
} public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        List<Integer> leftList = new ArrayList<>();
        List<Integer> rightList = new ArrayList<>();
        for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        }

        int left = Collections.max(leftList);
        int right = Collections.min(rightList);

        int result = Math.min(right, N) - Math.max(left, 1) + 1;
        if (result < 0) {
            result = 0;
        }

        System.out.println(result);
    }
} Main

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        List<Integer> leftList = new ArrayList<>();
        List<Integer> rightList = new ArrayList<>();
        for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        }

        int left = Collections.max(leftList);
        int right = Collections.min(rightList);

        int result = Math.min(right, N) - Math.max(left, 1) + 1;
        if (result < 0) {
            result = 0;
        }

        System.out.println(result);
    }
}