import java.util.*;
 
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+1];
        int[] r = new int[M+1];
        l[0] = Integer.parseInt(sc.next());
        r[0]= Integer.parseInt(sc.next());
        int max = r[0];
        int min = l[0];
        for(int i = 1; i < M; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        }
        
        System.out.println(max - min + 1);
    }
} import java.util.*; util.* java 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+1];
        int[] r = new int[M+1];
        l[0] = Integer.parseInt(sc.next());
        r[0]= Integer.parseInt(sc.next());
        int max = r[0];
        int min = l[0];
        for(int i = 1; i < M; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        }
        
        System.out.println(max - min + 1);
    }
} 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+1];
        int[] r = new int[M+1];
        l[0] = Integer.parseInt(sc.next());
        r[0]= Integer.parseInt(sc.next());
        int max = r[0];
        int min = l[0];
        for(int i = 1; i < M; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        }
        
        System.out.println(max - min + 1);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] l = new int[M+1];
        int[] r = new int[M+1];
        l[0] = Integer.parseInt(sc.next());
        r[0]= Integer.parseInt(sc.next());
        int max = r[0];
        int min = l[0];
        for(int i = 1; i < M; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        }
        
        System.out.println(max - min + 1);
    } 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+1]; l new int[M+1] M+1 M 1 int[] r = new int[M+1]; r new int[M+1] M+1 M 1 l[0] = Integer.parseInt(sc.next()) l[0] l 0 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r[0]= Integer.parseInt(sc.next()) r[0] r 0 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int max = r[0]; max r[0] r 0 int min = l[0]; min l[0] l 0 for(int i = 1; i < M; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        } int i = 1; int i = 1; i 1 i < M i M i++ i++ i {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        } {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        } 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 if(l[i] > min) {
                min = l[i];
            } l[i] > min l[i] l i min {
                min = l[i];
            } min = l[i] min l[i] l i if(r[i] < max) {
                max = r[i];
            } r[i] < max r[i] r i max {
                max = r[i];
            } max = r[i] max r[i] r i if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            } max - min < 0 max - min max min 0 {
                max = -1;
                min = 0;
                break;
            } max = -1 max -1 1 min = 0 min 0 break; System.out.println(max - min + 1) System.out.println System.out System System.out max - min + 1 max - min max min 1 String[] args args
import java.util.*;
 
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+1];
        int[] r = new int[M+1];
        l[0] = Integer.parseInt(sc.next());
        r[0]= Integer.parseInt(sc.next());
        int max = r[0];
        int min = l[0];
        for(int i = 1; i < M; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        }
        
        System.out.println(max - min + 1);
    }
}