import java.util.Scanner;
import java.util.Arrays;
 
public class Main{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        
        int count = 0;
        if(m != 1 && max(l) > min(r)){
            count = 0;
        }
        else{
            count = min(r) -max(l) +1;
        }
        System.out.println(count);
    }
    public static int max(int[] a){
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        }
        return max;
    }
    public static int min(int[] a){
        int min = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        }
        return min;
    }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util public class Main{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        
        int count = 0;
        if(m != 1 && max(l) > min(r)){
            count = 0;
        }
        else{
            count = min(r) -max(l) +1;
        }
        System.out.println(count);
    }
    public static int max(int[] a){
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        }
        return max;
    }
    public static int min(int[] a){
        int min = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        }
        return min;
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        
        int count = 0;
        if(m != 1 && max(l) > min(r)){
            count = 0;
        }
        else{
            count = min(r) -max(l) +1;
        }
        System.out.println(count);
    } main {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        
        int count = 0;
        if(m != 1 && max(l) > min(r)){
            count = 0;
        }
        else{
            count = min(r) -max(l) +1;
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] l = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        } l[i] = Integer.parseInt(sc.next()) l[i] l i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r[i] = Integer.parseInt(sc.next()) r[i] r i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int count = 0; count 0 if(m != 1 && max(l) > min(r)){
            count = 0;
        }
        else{
            count = min(r) -max(l) +1;
        } m != 1 && max(l) > min(r) m != 1 m 1 max(l) > min(r) max(l) max l min(r) min r {
            count = 0;
        } count = 0 count 0 {
            count = min(r) -max(l) +1;
        } count = min(r) -max(l) +1 count min(r) -max(l) +1 min(r) -max(l) min(r) min r max(l) max l 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public static int max(int[] a){
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        }
        return max;
    } max {
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        }
        return max;
    } int max = a[0]; max a[0] a 0 for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        } int i = 1; int i = 1; i 1 i < a.length i a.length a a.length i++ i++ i {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        } {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        } int v = a[i]; v a[i] a i if (v > max) {
              max = v;
            } v > max v max {
              max = v;
            } max = v max v return max; max int[] a a public static int min(int[] a){
        int min = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        }
        return min;
    } min {
        int min = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        }
        return min;
    } int min = a[0]; min a[0] a 0 for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        } int i = 1; int i = 1; i 1 i < a.length i a.length a a.length i++ i++ i {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        } {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        } int v = a[i]; v a[i] a i if (v < min) {
              min = v;
            } v < min v min {
              min = v;
            } min = v min v return min; min int[] a a public class Main{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        
        int count = 0;
        if(m != 1 && max(l) > min(r)){
            count = 0;
        }
        else{
            count = min(r) -max(l) +1;
        }
        System.out.println(count);
    }
    public static int max(int[] a){
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        }
        return max;
    }
    public static int min(int[] a){
        int min = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        }
        return min;
    }
} public class Main{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        
        int count = 0;
        if(m != 1 && max(l) > min(r)){
            count = 0;
        }
        else{
            count = min(r) -max(l) +1;
        }
        System.out.println(count);
    }
    public static int max(int[] a){
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        }
        return max;
    }
    public static int min(int[] a){
        int min = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        }
        return min;
    }
} Main
import java.util.Scanner;
import java.util.Arrays;
 
public class Main{
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        
        int count = 0;
        if(m != 1 && max(l) > min(r)){
            count = 0;
        }
        else{
            count = min(r) -max(l) +1;
        }
        System.out.println(count);
    }
    public static int max(int[] a){
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v > max) {
              max = v;
            }
        }
        return max;
    }
    public static int min(int[] a){
        int min = a[0];
        for (int i = 1; i < a.length; i++) {
            int v = a[i];
            if (v < min) {
              min = v;
            }
        }
        return min;
    }
}
