import java.util.ArrayList;
import java.util.Arrays;
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();
        int[] l = new int[m];
        int[] r = new int[m];
        ArrayList<Integer> id = new ArrayList<>();
 
        l[0] = scanner.nextInt();
        r[0] = scanner.nextInt();
        for (int i = l[0]; i <= r[0]; i++) {
            id.add(i);
        }
 
        if(m > 1) {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        }
        System.out.println(id.size());
    }
} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays 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();
        int[] l = new int[m];
        int[] r = new int[m];
        ArrayList<Integer> id = new ArrayList<>();
 
        l[0] = scanner.nextInt();
        r[0] = scanner.nextInt();
        for (int i = l[0]; i <= r[0]; i++) {
            id.add(i);
        }
 
        if(m > 1) {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        }
        System.out.println(id.size());
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        ArrayList<Integer> id = new ArrayList<>();
 
        l[0] = scanner.nextInt();
        r[0] = scanner.nextInt();
        for (int i = l[0]; i <= r[0]; i++) {
            id.add(i);
        }
 
        if(m > 1) {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        }
        System.out.println(id.size());
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        ArrayList<Integer> id = new ArrayList<>();
 
        l[0] = scanner.nextInt();
        r[0] = scanner.nextInt();
        for (int i = l[0]; i <= r[0]; i++) {
            id.add(i);
        }
 
        if(m > 1) {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        }
        System.out.println(id.size());
    } 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 int[] l = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m ArrayList<Integer> id = new ArrayList<>(); id new ArrayList<>() l[0] = scanner.nextInt() l[0] l 0 scanner.nextInt() scanner.nextInt scanner r[0] = scanner.nextInt() r[0] r 0 scanner.nextInt() scanner.nextInt scanner for (int i = l[0]; i <= r[0]; i++) {
            id.add(i);
        } int i = l[0]; int i = l[0]; i l[0] l 0 i <= r[0] i r[0] r 0 i++ i++ i {
            id.add(i);
        } {
            id.add(i);
        } id.add(i) id.add id i if(m > 1) {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        } m > 1 m 1 {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        } for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            } int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            } {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            } l[i] = scanner.nextInt() l[i] l i scanner.nextInt() scanner.nextInt scanner r[i] = scanner.nextInt() r[i] r i scanner.nextInt() scanner.nextInt scanner if (id.size() == 0) {
                    break;
                } id.size() == 0 id.size() id.size id 0 {
                    break;
                } break; while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                } id.get(0) < l[i] id.get(0) id.get id 0 l[i] l i {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                } id.remove(0) id.remove id 0 if (id.size() == 0) {
                        break;
                    } id.size() == 0 id.size() id.size id 0 {
                        break;
                    } break; if (id.size() == 0) {
                    break;
                } id.size() == 0 id.size() id.size id 0 {
                    break;
                } break; while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                } id.get(id.size() - 1) > r[i] id.get(id.size() - 1) id.get id id.size() - 1 id.size() id.size id 1 r[i] r i {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                } id.remove(id.size() - 1) id.remove id id.size() - 1 id.size() id.size id 1 if (id.size() == 0) {
                        break;
                    } id.size() == 0 id.size() id.size id 0 {
                        break;
                    } break; System.out.println(id.size()) System.out.println System.out System System.out id.size() id.size id 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();
        int[] l = new int[m];
        int[] r = new int[m];
        ArrayList<Integer> id = new ArrayList<>();
 
        l[0] = scanner.nextInt();
        r[0] = scanner.nextInt();
        for (int i = l[0]; i <= r[0]; i++) {
            id.add(i);
        }
 
        if(m > 1) {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        }
        System.out.println(id.size());
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        ArrayList<Integer> id = new ArrayList<>();
 
        l[0] = scanner.nextInt();
        r[0] = scanner.nextInt();
        for (int i = l[0]; i <= r[0]; i++) {
            id.add(i);
        }
 
        if(m > 1) {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        }
        System.out.println(id.size());
    }
} Main
import java.util.ArrayList;
import java.util.Arrays;
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();
        int[] l = new int[m];
        int[] r = new int[m];
        ArrayList<Integer> id = new ArrayList<>();
 
        l[0] = scanner.nextInt();
        r[0] = scanner.nextInt();
        for (int i = l[0]; i <= r[0]; i++) {
            id.add(i);
        }
 
        if(m > 1) {
            for (int i = 1; i < m; i++) {
                l[i] = scanner.nextInt();
                r[i] = scanner.nextInt();
 
                if (id.size() == 0) {
                    break;
                }
 
                while (id.get(0) < l[i]) {
                    id.remove(0);
                    if (id.size() == 0) {
                        break;
                    }
                }
                              if (id.size() == 0) {
                    break;
                }
                while (id.get(id.size() - 1) > r[i]) {
                    id.remove(id.size() - 1);
                    if (id.size() == 0) {
                        break;
                    }
                }
            }
        }
        System.out.println(id.size());
    }
}