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 Lin = 0;
    	int Rin = Integer.MAX_VALUE;
    	for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	}
    	System.out.println(Lin <= Rin ? Rin - Lin + 1 : 0);
    }
} 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 Lin = 0;
    	int Rin = Integer.MAX_VALUE;
    	for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	}
    	System.out.println(Lin <= Rin ? Rin - Lin + 1 : 0);
    }
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int M = sc.nextInt();
    	int Lin = 0;
    	int Rin = Integer.MAX_VALUE;
    	for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	}
    	System.out.println(Lin <= Rin ? Rin - Lin + 1 : 0);
    } main {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int M = sc.nextInt();
    	int Lin = 0;
    	int Rin = Integer.MAX_VALUE;
    	for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	}
    	System.out.println(Lin <= Rin ? Rin - Lin + 1 : 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 Lin = 0; Lin 0 int Rin = Integer.MAX_VALUE; Rin Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	} {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	} int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc if (Lin < L) {
    			Lin = L;
    		} Lin < L Lin L {
    			Lin = L;
    		} Lin = L Lin L if (R < Rin) {
    			Rin = R;
    		} R < Rin R Rin {
    			Rin = R;
    		} Rin = R Rin R System.out.println(Lin <= Rin ? Rin - Lin + 1 : 0) System.out.println System.out System System.out Lin <= Rin ? Rin - Lin + 1 : 0 Lin <= Rin Lin Rin Rin - Lin + 1 Rin - Lin Rin Lin 1 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 Lin = 0;
    	int Rin = Integer.MAX_VALUE;
    	for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	}
    	System.out.println(Lin <= Rin ? Rin - Lin + 1 : 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 Lin = 0;
    	int Rin = Integer.MAX_VALUE;
    	for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	}
    	System.out.println(Lin <= Rin ? Rin - Lin + 1 : 0);
    }
} 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 Lin = 0;
    	int Rin = Integer.MAX_VALUE;
    	for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	}
    	System.out.println(Lin <= Rin ? Rin - Lin + 1 : 0);
    }
}