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[] ar = new int[N+1];
        for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        }
        int cnt  = 0;
        if(ar[0] == M) cnt++;
        for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        }
        System.out.println(cnt);
    }
} 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[] ar = new int[N+1];
        for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        }
        int cnt  = 0;
        if(ar[0] == M) cnt++;
        for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        }
        System.out.println(cnt);
    }
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] ar = new int[N+1];
        for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        }
        int cnt  = 0;
        if(ar[0] == M) cnt++;
        for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        }
        System.out.println(cnt);
    } main {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] ar = new int[N+1];
        for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        }
        int cnt  = 0;
        if(ar[0] == M) cnt++;
        for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        }
        System.out.println(cnt);
    } 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[] ar = new int[N+1]; ar new int[N+1] N+1 N 1 for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        } int i = 0; int i = 0; i 0 i<M i M i++ i++ i {
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        } {
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        } int l = sc.nextInt()-1; l sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc ar[l]++ ar[l] ar l ar[r]-- ar[r] ar r int cnt  = 0; cnt 0 if(ar[0] == M) cnt++; ar[0] == M ar[0] ar 0 M cnt++ cnt for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        } int i = 1; int i = 1; i 1 i<N+1 i N+1 N 1 i++ i++ i {
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        } {
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        } ar[i]+=ar[i-1] ar[i] ar i ar[i-1] ar i-1 i 1 if(ar[i] == M) cnt++; ar[i] == M ar[i] ar i M cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt 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[] ar = new int[N+1];
        for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        }
        int cnt  = 0;
        if(ar[0] == M) cnt++;
        for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        }
        System.out.println(cnt);
    }
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] ar = new int[N+1];
        for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        }
        int cnt  = 0;
        if(ar[0] == M) cnt++;
        for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        }
        System.out.println(cnt);
    }
} 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[] ar = new int[N+1];
        for(int i = 0; i<M; i++){
            int l = sc.nextInt()-1;
            int r = sc.nextInt();
            ar[l]++;
            ar[r]--;
        }
        int cnt  = 0;
        if(ar[0] == M) cnt++;
        for(int i = 1; i<N+1; i++){
            ar[i]+=ar[i-1];
            if(ar[i] == M) cnt++;
        }
        System.out.println(cnt);
    }
}