import 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());
        }
        int l = Collections.max(L);
        int r = Collections.min(R);

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

    }

} import java.util.*; util.* java 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());
        }
        int l = Collections.max(L);
        int r = Collections.min(R);

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

    }

} 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());
        }
        int l = Collections.max(L);
        int r = Collections.min(R);

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

    } 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());
        }
        int l = Collections.max(L);
        int r = Collections.min(R);

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

    } 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 int l = Collections.max(L); l Collections.max(L) Collections.max Collections L int r = Collections.min(R); r Collections.min(R) Collections.min Collections R if (l>r){
            System.out.println(0);
        }else {
            System.out.println(r-l+1);
        } l>r l r {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(r-l+1);
        } System.out.println(r-l+1) System.out.println System.out System System.out r-l+1 r-l r l 1 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());
        }
        int l = Collections.max(L);
        int r = Collections.min(R);

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

    }

} 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());
        }
        int l = Collections.max(L);
        int r = Collections.min(R);

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

    }

} Main
import 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());
        }
        int l = Collections.max(L);
        int r = Collections.min(R);

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

    }

}