import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int max=N+1;
        int min=0;
        for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        }
        //int K = sc.nextInt();
        //long N = sc.nextLong();
        int res = Math.max(max-min+1,0);
        

        
        System.out.println(res);
        }
    } import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int max=N+1;
        int min=0;
        for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        }
        //int K = sc.nextInt();
        //long N = sc.nextLong();
        int res = Math.max(max-min+1,0);
        

        
        System.out.println(res);
        }
    } Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int max=N+1;
        int min=0;
        for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        }
        //int K = sc.nextInt();
        //long N = sc.nextLong();
        int res = Math.max(max-min+1,0);
        

        
        System.out.println(res);
        } main {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int max=N+1;
        int min=0;
        for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        }
        //int K = sc.nextInt();
        //long N = sc.nextLong();
        int res = Math.max(max-min+1,0);
        

        
        System.out.println(res);
        } 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[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M int max=N+1; max N+1 N 1 int min=0; min 0 for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        } int i=0; int i=0; i 0 i<M i M i++ i++ i {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        } {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        } L[i]=sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i]=sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc min = Math.max(min,L[i]) min Math.max(min,L[i]) Math.max Math min L[i] L i max = Math.min(max,R[i]) max Math.min(max,R[i]) Math.min Math max R[i] R i int res = Math.max(max-min+1,0); res Math.max(max-min+1,0) Math.max Math max-min+1 max-min max min 1 0 System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int max=N+1;
        int min=0;
        for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        }
        //int K = sc.nextInt();
        //long N = sc.nextLong();
        int res = Math.max(max-min+1,0);
        

        
        System.out.println(res);
        }
    } public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int max=N+1;
        int min=0;
        for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        }
        //int K = sc.nextInt();
        //long N = sc.nextLong();
        int res = Math.max(max-min+1,0);
        

        
        System.out.println(res);
        }
    } Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int max=N+1;
        int min=0;
        for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        }
        //int K = sc.nextInt();
        //long N = sc.nextLong();
        int res = Math.max(max-min+1,0);
        

        
        System.out.println(res);
        }
    }