import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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();

        ArrayList<Integer> l = new ArrayList<>();
        ArrayList<Integer> r = new ArrayList<>();


        for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        }

        if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        }
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections 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();

        ArrayList<Integer> l = new ArrayList<>();
        ArrayList<Integer> r = new ArrayList<>();


        for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        }

        if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        ArrayList<Integer> l = new ArrayList<>();
        ArrayList<Integer> r = new ArrayList<>();


        for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        }

        if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        ArrayList<Integer> l = new ArrayList<>();
        ArrayList<Integer> r = new ArrayList<>();


        for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        }

        if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        }
    } 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 ArrayList<Integer> l = new ArrayList<>(); l new ArrayList<>() ArrayList<Integer> r = new ArrayList<>(); r new ArrayList<>() for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        } {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        } l.add(scanner.nextInt()) l.add l scanner.nextInt() scanner.nextInt scanner r.add(scanner.nextInt()) r.add r scanner.nextInt() scanner.nextInt scanner if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        } Collections.min(r) >= Collections.max(l) Collections.min(r) Collections.min Collections r Collections.max(l) Collections.max Collections l {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } System.out.println(Collections.min(r) - Collections.max(l) + 1) System.out.println System.out System System.out Collections.min(r) - Collections.max(l) + 1 Collections.min(r) - Collections.max(l) Collections.min(r) Collections.min Collections r Collections.max(l) Collections.max Collections l 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 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();

        ArrayList<Integer> l = new ArrayList<>();
        ArrayList<Integer> r = new ArrayList<>();


        for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        }

        if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        ArrayList<Integer> l = new ArrayList<>();
        ArrayList<Integer> r = new ArrayList<>();


        for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        }

        if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        }
    }
} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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();

        ArrayList<Integer> l = new ArrayList<>();
        ArrayList<Integer> r = new ArrayList<>();


        for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        }

        if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        }
    }
}