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

        List<Integer> num1 = new ArrayList<>();
        List<Integer> num2 = new ArrayList<>();


        for (int i = 0; i < m; i++){

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        }
        int max_num = Collections.max(num1);
        int min_num = Collections.min(num2);

        if (max_num <= min_num){
            System.out.println(min_num - max_num + 1);
        }else{
            System.out.println(0);
        }

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

        List<Integer> num1 = new ArrayList<>();
        List<Integer> num2 = new ArrayList<>();


        for (int i = 0; i < m; i++){

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        }
        int max_num = Collections.max(num1);
        int min_num = Collections.min(num2);

        if (max_num <= min_num){
            System.out.println(min_num - max_num + 1);
        }else{
            System.out.println(0);
        }

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

        Scanner sc = new Scanner(System.in);


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

        List<Integer> num1 = new ArrayList<>();
        List<Integer> num2 = new ArrayList<>();


        for (int i = 0; i < m; i++){

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        }
        int max_num = Collections.max(num1);
        int min_num = Collections.min(num2);

        if (max_num <= min_num){
            System.out.println(min_num - max_num + 1);
        }else{
            System.out.println(0);
        }

    } main {

        Scanner sc = new Scanner(System.in);


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

        List<Integer> num1 = new ArrayList<>();
        List<Integer> num2 = new ArrayList<>();


        for (int i = 0; i < m; i++){

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        }
        int max_num = Collections.max(num1);
        int min_num = Collections.min(num2);

        if (max_num <= min_num){
            System.out.println(min_num - max_num + 1);
        }else{
            System.out.println(0);
        }

    } 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 List<Integer> num1 = new ArrayList<>(); num1 new ArrayList<>() List<Integer> num2 = new ArrayList<>(); num2 new ArrayList<>() for (int i = 0; i < m; i++){

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        } {

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        } num1.add(sc.nextInt()) num1.add num1 sc.nextInt() sc.nextInt sc num2.add(sc.nextInt()) num2.add num2 sc.nextInt() sc.nextInt sc int max_num = Collections.max(num1); max_num Collections.max(num1) Collections.max Collections num1 int min_num = Collections.min(num2); min_num Collections.min(num2) Collections.min Collections num2 if (max_num <= min_num){
            System.out.println(min_num - max_num + 1);
        }else{
            System.out.println(0);
        } max_num <= min_num max_num min_num {
            System.out.println(min_num - max_num + 1);
        } System.out.println(min_num - max_num + 1) System.out.println System.out System System.out min_num - max_num + 1 min_num - max_num min_num max_num 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 sc = new Scanner(System.in);


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

        List<Integer> num1 = new ArrayList<>();
        List<Integer> num2 = new ArrayList<>();


        for (int i = 0; i < m; i++){

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        }
        int max_num = Collections.max(num1);
        int min_num = Collections.min(num2);

        if (max_num <= min_num){
            System.out.println(min_num - max_num + 1);
        }else{
            System.out.println(0);
        }

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

        Scanner sc = new Scanner(System.in);


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

        List<Integer> num1 = new ArrayList<>();
        List<Integer> num2 = new ArrayList<>();


        for (int i = 0; i < m; i++){

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        }
        int max_num = Collections.max(num1);
        int min_num = Collections.min(num2);

        if (max_num <= min_num){
            System.out.println(min_num - max_num + 1);
        }else{
            System.out.println(0);
        }

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

        List<Integer> num1 = new ArrayList<>();
        List<Integer> num2 = new ArrayList<>();


        for (int i = 0; i < m; i++){

            num1.add(sc.nextInt());
            num2.add(sc.nextInt());
        }
        int max_num = Collections.max(num1);
        int min_num = Collections.min(num2);

        if (max_num <= min_num){
            System.out.println(min_num - max_num + 1);
        }else{
            System.out.println(0);
        }

    }
}
