
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lhigh = 0;
        int rlow = 1000000;
        int tmp;
        for(int i = 0;i < m;i++){
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        }
        tmp = rlow-lhigh + 1;
        if(tmp < 0) tmp = 0;
        System.out.print(tmp);
    }
    
} import java.util.Scanner; Scanner java.util public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lhigh = 0;
        int rlow = 1000000;
        int tmp;
        for(int i = 0;i < m;i++){
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        }
        tmp = rlow-lhigh + 1;
        if(tmp < 0) tmp = 0;
        System.out.print(tmp);
    }
    
} Main /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lhigh = 0;
        int rlow = 1000000;
        int tmp;
        for(int i = 0;i < m;i++){
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        }
        tmp = rlow-lhigh + 1;
        if(tmp < 0) tmp = 0;
        System.out.print(tmp);
    } main {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lhigh = 0;
        int rlow = 1000000;
        int tmp;
        for(int i = 0;i < m;i++){
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        }
        tmp = rlow-lhigh + 1;
        if(tmp < 0) tmp = 0;
        System.out.print(tmp);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int lhigh = 0; lhigh 0 int rlow = 1000000; rlow 1000000 int tmp; tmp for(int i = 0;i < m;i++){
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        } {
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        } tmp = sc.nextInt() tmp sc.nextInt() sc.nextInt sc if(lhigh < tmp)lhigh = tmp; lhigh < tmp lhigh tmp lhigh = tmp lhigh tmp tmp = sc.nextInt() tmp sc.nextInt() sc.nextInt sc if(rlow > tmp) rlow = tmp; rlow > tmp rlow tmp rlow = tmp rlow tmp tmp = rlow-lhigh + 1 tmp rlow-lhigh + 1 rlow-lhigh rlow lhigh 1 if(tmp < 0) tmp = 0; tmp < 0 tmp 0 tmp = 0 tmp 0 System.out.print(tmp) System.out.print System.out System System.out tmp String[] args args public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lhigh = 0;
        int rlow = 1000000;
        int tmp;
        for(int i = 0;i < m;i++){
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        }
        tmp = rlow-lhigh + 1;
        if(tmp < 0) tmp = 0;
        System.out.print(tmp);
    }
    
} public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lhigh = 0;
        int rlow = 1000000;
        int tmp;
        for(int i = 0;i < m;i++){
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        }
        tmp = rlow-lhigh + 1;
        if(tmp < 0) tmp = 0;
        System.out.print(tmp);
    }
    
} Main

import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lhigh = 0;
        int rlow = 1000000;
        int tmp;
        for(int i = 0;i < m;i++){
            tmp = sc.nextInt();
            if(lhigh < tmp)lhigh = tmp;
            tmp = sc.nextInt();
            if(rlow > tmp) rlow = tmp;
        }
        tmp = rlow-lhigh + 1;
        if(tmp < 0) tmp = 0;
        System.out.print(tmp);
    }
    
}
