import java.util.Scanner;
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];
		
		for(int i = 0;i < m;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		
		int keyleft = 0;
		int keyright = Integer.MAX_VALUE;
		
		int ans = 0;
		
		for(int i = 0;i < m;i++){
			if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			}
			if(l[i] > keyleft){
				 keyleft = l[i];
			}
			if(r[i] < keyright ){
				keyright = r[i];
			}
		}
		
		System.out.print(keyright-keyleft+1);
		
	}


	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}

 import java.util.Scanner; Scanner java.util 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];
		
		for(int i = 0;i < m;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		
		int keyleft = 0;
		int keyright = Integer.MAX_VALUE;
		
		int ans = 0;
		
		for(int i = 0;i < m;i++){
			if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			}
			if(l[i] > keyleft){
				 keyleft = l[i];
			}
			if(r[i] < keyright ){
				keyright = r[i];
			}
		}
		
		System.out.print(keyright-keyleft+1);
		
	}


	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





} 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];
		
		for(int i = 0;i < m;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		
		int keyleft = 0;
		int keyright = Integer.MAX_VALUE;
		
		int ans = 0;
		
		for(int i = 0;i < m;i++){
			if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			}
			if(l[i] > keyleft){
				 keyleft = l[i];
			}
			if(r[i] < keyright ){
				keyright = r[i];
			}
		}
		
		System.out.print(keyright-keyleft+1);
		
	} 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];
		
		for(int i = 0;i < m;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		
		int keyleft = 0;
		int keyright = Integer.MAX_VALUE;
		
		int ans = 0;
		
		for(int i = 0;i < m;i++){
			if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			}
			if(l[i] > keyleft){
				 keyleft = l[i];
			}
			if(r[i] < keyright ){
				keyright = r[i];
			}
		}
		
		System.out.print(keyright-keyleft+1);
		
	} 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 for(int i = 0;i < m;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} 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 int keyleft = 0; keyleft 0 int keyright = Integer.MAX_VALUE; keyright Integer.MAX_VALUE Integer Integer.MAX_VALUE int ans = 0; ans 0 for(int i = 0;i < m;i++){
			if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			}
			if(l[i] > keyleft){
				 keyleft = l[i];
			}
			if(r[i] < keyright ){
				keyright = r[i];
			}
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			}
			if(l[i] > keyleft){
				 keyleft = l[i];
			}
			if(r[i] < keyright ){
				keyright = r[i];
			}
		} {
			if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			}
			if(l[i] > keyleft){
				 keyleft = l[i];
			}
			if(r[i] < keyright ){
				keyright = r[i];
			}
		} if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			} l[i] > keyright || r[i] < keyleft l[i] > keyright l[i] l i keyright r[i] < keyleft r[i] r i keyleft {
				System.out.println(0);
				return;
			} System.out.println(0) System.out.println System.out System System.out 0 return; if(l[i] > keyleft){
				 keyleft = l[i];
			} l[i] > keyleft l[i] l i keyleft {
				 keyleft = l[i];
			} keyleft = l[i] keyleft l[i] l i if(r[i] < keyright ){
				keyright = r[i];
			} r[i] < keyright r[i] r i keyright {
				keyright = r[i];
			} keyright = r[i] keyright r[i] r i System.out.print(keyright-keyleft+1) System.out.print System.out System System.out keyright-keyleft+1 keyright-keyleft keyright keyleft 1 String[] args args static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	} gcd {				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	} if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		} b == 0 b 0 {
			return a;
		} return a; a {
			return gcd(b, a%b);
		} return gcd(b, a%b); gcd(b, a%b) gcd b a%b a b int a a int b b class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
} Pair int from; from int end; end @Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	} compareTo {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	} Pair otherpair = (Pair)other; otherpair (Pair)other return from - otherpair.from; from - otherpair.from from otherpair.from otherpair otherpair.from Object other other Comparable
import java.util.Scanner;
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];
		
		for(int i = 0;i < m;i++){
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		
		int keyleft = 0;
		int keyright = Integer.MAX_VALUE;
		
		int ans = 0;
		
		for(int i = 0;i < m;i++){
			if(l[i] > keyright || r[i] < keyleft ){
				System.out.println(0);
				return;
			}
			if(l[i] > keyleft){
				 keyleft = l[i];
			}
			if(r[i] < keyright ){
				keyright = r[i];
			}
		}
		
		System.out.print(keyright-keyleft+1);
		
	}


	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}


