import java.util.Scanner;

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());
        }
        
        int maxL = 1;
        int minR = n;
        for(int i = 0; i < m; i++){
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        }
        
        if((minR - maxL) < 0){
            System.out.println(0);
        }else{
            System.out.println(minR - maxL +1);
        }
    }
} import java.util.Scanner; Scanner 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());
        }
        
        int maxL = 1;
        int minR = n;
        for(int i = 0; i < m; i++){
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        }
        
        if((minR - maxL) < 0){
            System.out.println(0);
        }else{
            System.out.println(minR - maxL +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];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int maxL = 1;
        int minR = n;
        for(int i = 0; i < m; i++){
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        }
        
        if((minR - maxL) < 0){
            System.out.println(0);
        }else{
            System.out.println(minR - maxL +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];
        int[] r = new int[m];
        for(int i = 0; i < m; i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        
        int maxL = 1;
        int minR = n;
        for(int i = 0; i < m; i++){
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        }
        
        if((minR - maxL) < 0){
            System.out.println(0);
        }else{
            System.out.println(minR - maxL +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]; 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 int maxL = 1; maxL 1 int minR = n; minR n for(int i = 0; i < m; i++){
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        } {
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        } if(l[i] > maxL){
                maxL = l[i];
            } l[i] > maxL l[i] l i maxL {
                maxL = l[i];
            } maxL = l[i] maxL l[i] l i if(r[i] < minR){
                minR = r[i];
            } r[i] < minR r[i] r i minR {
                minR = r[i];
            } minR = r[i] minR r[i] r i if((minR - maxL) < 0){
            System.out.println(0);
        }else{
            System.out.println(minR - maxL +1);
        } (minR - maxL) < 0 (minR - maxL) minR maxL 0 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(minR - maxL +1);
        } System.out.println(minR - maxL +1) System.out.println System.out System System.out minR - maxL +1 minR - maxL minR maxL 1 String[] args args 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());
        }
        
        int maxL = 1;
        int minR = n;
        for(int i = 0; i < m; i++){
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        }
        
        if((minR - maxL) < 0){
            System.out.println(0);
        }else{
            System.out.println(minR - maxL +1);
        }
    }
} 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());
        }
        
        int maxL = 1;
        int minR = n;
        for(int i = 0; i < m; i++){
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        }
        
        if((minR - maxL) < 0){
            System.out.println(0);
        }else{
            System.out.println(minR - maxL +1);
        }
    }
} Main
import java.util.Scanner;

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());
        }
        
        int maxL = 1;
        int minR = n;
        for(int i = 0; i < m; i++){
            if(l[i] > maxL){
                maxL = l[i];
            }
            if(r[i] < minR){
                minR = r[i];
            }
        }
        
        if((minR - maxL) < 0){
            System.out.println(0);
        }else{
            System.out.println(minR - maxL +1);
        }
    }
}