import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int min = 0;
        int max = (int)Math.pow(10, 5) + 1;
        for(int i = 0; i < m; i++){
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        }
        System.out.println(max >= min ? max - min + 1 : 0);
        scan.close();
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int min = 0;
        int max = (int)Math.pow(10, 5) + 1;
        for(int i = 0; i < m; i++){
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        }
        System.out.println(max >= min ? max - min + 1 : 0);
        scan.close();
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int min = 0;
        int max = (int)Math.pow(10, 5) + 1;
        for(int i = 0; i < m; i++){
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        }
        System.out.println(max >= min ? max - min + 1 : 0);
        scan.close();
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int min = 0;
        int max = (int)Math.pow(10, 5) + 1;
        for(int i = 0; i < m; i++){
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        }
        System.out.println(max >= min ? max - min + 1 : 0);
        scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan 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] = scan.nextInt();
            r[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        } {
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        } l[i] = scan.nextInt() l[i] l i scan.nextInt() scan.nextInt scan r[i] = scan.nextInt() r[i] r i scan.nextInt() scan.nextInt scan int min = 0; min 0 int max = (int)Math.pow(10, 5) + 1; max (int)Math.pow(10, 5) + 1 (int)Math.pow(10, 5) Math.pow Math 10 5 1 for(int i = 0; i < m; i++){
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        } {
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        } if(min < l[i]) min = l[i]; min < l[i] min l[i] l i min = l[i] min l[i] l i if(max > r[i]) max = r[i]; max > r[i] max r[i] r i max = r[i] max r[i] r i System.out.println(max >= min ? max - min + 1 : 0) System.out.println System.out System System.out max >= min ? max - min + 1 : 0 max >= min max min max - min + 1 max - min max min 1 0 scan.close() scan.close scan String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int min = 0;
        int max = (int)Math.pow(10, 5) + 1;
        for(int i = 0; i < m; i++){
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        }
        System.out.println(max >= min ? max - min + 1 : 0);
        scan.close();
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int min = 0;
        int max = (int)Math.pow(10, 5) + 1;
        for(int i = 0; i < m; i++){
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        }
        System.out.println(max >= min ? max - min + 1 : 0);
        scan.close();
    }
} Main
import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int min = 0;
        int max = (int)Math.pow(10, 5) + 1;
        for(int i = 0; i < m; i++){
            if(min < l[i]) min = l[i];
            if(max > r[i]) max = r[i];
        }
        System.out.println(max >= min ? max - min + 1 : 0);
        scan.close();
    }
}