import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        Map<Integer,Integer> numCanPass = new HashMap<>();
        for(int i=1; i<=N; i++){
            numCanPass.put(i, 0);
        }
        int minCard = 1;
        int maxCard = N;
        for(int i=0; i<M; i++){
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        }
        if(minCard>maxCard){
            System.out.println(String.valueOf(0));
        }else{
            System.out.println(String.valueOf(maxCard - minCard + 1));
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        Map<Integer,Integer> numCanPass = new HashMap<>();
        for(int i=1; i<=N; i++){
            numCanPass.put(i, 0);
        }
        int minCard = 1;
        int maxCard = N;
        for(int i=0; i<M; i++){
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        }
        if(minCard>maxCard){
            System.out.println(String.valueOf(0));
        }else{
            System.out.println(String.valueOf(maxCard - minCard + 1));
        }
    }
} Main public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        Map<Integer,Integer> numCanPass = new HashMap<>();
        for(int i=1; i<=N; i++){
            numCanPass.put(i, 0);
        }
        int minCard = 1;
        int maxCard = N;
        for(int i=0; i<M; i++){
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        }
        if(minCard>maxCard){
            System.out.println(String.valueOf(0));
        }else{
            System.out.println(String.valueOf(maxCard - minCard + 1));
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        Map<Integer,Integer> numCanPass = new HashMap<>();
        for(int i=1; i<=N; i++){
            numCanPass.put(i, 0);
        }
        int minCard = 1;
        int maxCard = N;
        for(int i=0; i<M; i++){
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        }
        if(minCard>maxCard){
            System.out.println(String.valueOf(0));
        }else{
            System.out.println(String.valueOf(maxCard - minCard + 1));
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int M = scanner.nextInt(); M scanner.nextInt() scanner.nextInt scanner Map<Integer,Integer> numCanPass = new HashMap<>(); numCanPass new HashMap<>() for(int i=1; i<=N; i++){
            numCanPass.put(i, 0);
        } int i=1; int i=1; i 1 i<=N i N i++ i++ i {
            numCanPass.put(i, 0);
        } {
            numCanPass.put(i, 0);
        } numCanPass.put(i, 0) numCanPass.put numCanPass i 0 int minCard = 1; minCard 1 int maxCard = N; maxCard N for(int i=0; i<M; i++){
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        } int i=0; int i=0; i 0 i<M i M i++ i++ i {
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        } {
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        } int L = scanner.nextInt(); L scanner.nextInt() scanner.nextInt scanner int R = scanner.nextInt(); R scanner.nextInt() scanner.nextInt scanner minCard = Math.max(minCard,L) minCard Math.max(minCard,L) Math.max Math minCard L maxCard = Math.min(maxCard,R) maxCard Math.min(maxCard,R) Math.min Math maxCard R if(minCard>maxCard){
            System.out.println(String.valueOf(0));
        }else{
            System.out.println(String.valueOf(maxCard - minCard + 1));
        } minCard>maxCard minCard maxCard {
            System.out.println(String.valueOf(0));
        } System.out.println(String.valueOf(0)) System.out.println System.out System System.out String.valueOf(0) String.valueOf String 0 {
            System.out.println(String.valueOf(maxCard - minCard + 1));
        } System.out.println(String.valueOf(maxCard - minCard + 1)) System.out.println System.out System System.out String.valueOf(maxCard - minCard + 1) String.valueOf String maxCard - minCard + 1 maxCard - minCard maxCard minCard 1 String args[] args public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        Map<Integer,Integer> numCanPass = new HashMap<>();
        for(int i=1; i<=N; i++){
            numCanPass.put(i, 0);
        }
        int minCard = 1;
        int maxCard = N;
        for(int i=0; i<M; i++){
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        }
        if(minCard>maxCard){
            System.out.println(String.valueOf(0));
        }else{
            System.out.println(String.valueOf(maxCard - minCard + 1));
        }
    }
} public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        Map<Integer,Integer> numCanPass = new HashMap<>();
        for(int i=1; i<=N; i++){
            numCanPass.put(i, 0);
        }
        int minCard = 1;
        int maxCard = N;
        for(int i=0; i<M; i++){
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        }
        if(minCard>maxCard){
            System.out.println(String.valueOf(0));
        }else{
            System.out.println(String.valueOf(maxCard - minCard + 1));
        }
    }
} Main
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        Map<Integer,Integer> numCanPass = new HashMap<>();
        for(int i=1; i<=N; i++){
            numCanPass.put(i, 0);
        }
        int minCard = 1;
        int maxCard = N;
        for(int i=0; i<M; i++){
            int L = scanner.nextInt();
            int R = scanner.nextInt();
            
            minCard = Math.max(minCard,L);
            maxCard = Math.min(maxCard,R);
        }
        if(minCard>maxCard){
            System.out.println(String.valueOf(0));
        }else{
            System.out.println(String.valueOf(maxCard - minCard + 1));
        }
    }
}