    import java.util.Scanner;
     
    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 = 0;
    		int R = N;
     
    		for (int i=0; i<M; i++) {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		}
     
    		int ans = R-L+1;
    		if (ans>0) System.out.println(ans);
    		else System.out.println(0);
    	}
    } import java.util.Scanner; Scanner 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 = 0;
    		int R = N;
     
    		for (int i=0; i<M; i++) {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		}
     
    		int ans = R-L+1;
    		if (ans>0) System.out.println(ans);
    		else System.out.println(0);
    	}
    } Main public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int N = sc.nextInt();
    		int M = sc.nextInt();
     
    		int L = 0;
    		int R = N;
     
    		for (int i=0; i<M; i++) {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		}
     
    		int ans = R-L+1;
    		if (ans>0) System.out.println(ans);
    		else System.out.println(0);
    	} main {
    		Scanner sc = new Scanner(System.in);
    		int N = sc.nextInt();
    		int M = sc.nextInt();
     
    		int L = 0;
    		int R = N;
     
    		for (int i=0; i<M; i++) {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		}
     
    		int ans = R-L+1;
    		if (ans>0) System.out.println(ans);
    		else System.out.println(0);
    	} 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 = 0; L 0 int R = N; R N for (int i=0; i<M; i++) {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		} {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		} int L2 = sc.nextInt(); L2 sc.nextInt() sc.nextInt sc int R2 = sc.nextInt(); R2 sc.nextInt() sc.nextInt sc L = Math.max(L, L2) L Math.max(L, L2) Math.max Math L L2 R = Math.min(R, R2) R Math.min(R, R2) Math.min Math R R2 int ans = R-L+1; ans R-L+1 R-L R L 1 if (ans>0) System.out.println(ans);
    		else System.out.println(0); ans>0 ans 0 System.out.println(ans) System.out.println System.out System System.out ans System.out.println(0) System.out.println System.out System System.out 0 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 = 0;
    		int R = N;
     
    		for (int i=0; i<M; i++) {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		}
     
    		int ans = R-L+1;
    		if (ans>0) System.out.println(ans);
    		else System.out.println(0);
    	}
    } 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 = 0;
    		int R = N;
     
    		for (int i=0; i<M; i++) {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		}
     
    		int ans = R-L+1;
    		if (ans>0) System.out.println(ans);
    		else System.out.println(0);
    	}
    } Main
    import java.util.Scanner;
     
    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 = 0;
    		int R = N;
     
    		for (int i=0; i<M; i++) {
    			int L2 = sc.nextInt();
    			int R2 = sc.nextInt();
     
    			L = Math.max(L, L2);
    			R = Math.min(R, R2);
    		}
     
    		int ans = R-L+1;
    		if (ans>0) System.out.println(ans);
    		else System.out.println(0);
    	}
    }