import java.util.*;
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt(), M = sc.nextInt();
	    int min = 0, max = 100000;
	    for (int i=0; i<M; i++) {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    }
	    int ans = Math.max(max - min + 1,0);
		System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt(), M = sc.nextInt();
	    int min = 0, max = 100000;
	    for (int i=0; i<M; i++) {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    }
	    int ans = Math.max(max - min + 1,0);
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt(), M = sc.nextInt();
	    int min = 0, max = 100000;
	    for (int i=0; i<M; i++) {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    }
	    int ans = Math.max(max - min + 1,0);
		System.out.println(ans);
	} main {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt(), M = sc.nextInt();
	    int min = 0, max = 100000;
	    for (int i=0; i<M; i++) {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    }
	    int ans = Math.max(max - min + 1,0);
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt() N sc.nextInt() sc.nextInt sc M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int min = 0 min 0 max = 100000; max 100000 for (int i=0; i<M; i++) {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    } int i=0; int i=0; i 0 i<M i M i++ i++ i {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    } {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    } int l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt(); r sc.nextInt() sc.nextInt sc min = Math.max(min,l) min Math.max(min,l) Math.max Math min l max = Math.min(max,r) max Math.min(max,r) Math.min Math max r int ans = Math.max(max - min + 1,0); ans Math.max(max - min + 1,0) Math.max Math max - min + 1 max - min max min 1 0 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt(), M = sc.nextInt();
	    int min = 0, max = 100000;
	    for (int i=0; i<M; i++) {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    }
	    int ans = Math.max(max - min + 1,0);
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt(), M = sc.nextInt();
	    int min = 0, max = 100000;
	    for (int i=0; i<M; i++) {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    }
	    int ans = Math.max(max - min + 1,0);
		System.out.println(ans);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt(), M = sc.nextInt();
	    int min = 0, max = 100000;
	    for (int i=0; i<M; i++) {
	        int l = sc.nextInt(), r = sc.nextInt();
	        min = Math.max(min,l);
	        max = Math.min(max,r);
	    }
	    int ans = Math.max(max - min + 1,0);
		System.out.println(ans);
	}
}