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 Rmin=1000000,Lmax=0,buff;
		for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		}
		System.out.println(Math.max(0, Rmin-Lmax+1));

	}
}

 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 Rmin=1000000,Lmax=0,buff;
		for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		}
		System.out.println(Math.max(0, Rmin-Lmax+1));

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int Rmin=1000000,Lmax=0,buff;
		for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		}
		System.out.println(Math.max(0, Rmin-Lmax+1));

	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int Rmin=1000000,Lmax=0,buff;
		for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		}
		System.out.println(Math.max(0, Rmin-Lmax+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 Rmin=1000000 Rmin 1000000 Lmax=0 Lmax 0 buff; buff for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		} int i=0; int i=0; i 0 i<m i m i++ i++ i {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		} {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		} buff=sc.nextInt() buff sc.nextInt() sc.nextInt sc if(buff>Lmax) {
				Lmax=buff;
			} buff>Lmax buff Lmax {
				Lmax=buff;
			} Lmax=buff Lmax buff buff=sc.nextInt() buff sc.nextInt() sc.nextInt sc if(buff<Rmin) {
				Rmin=buff;
			} buff<Rmin buff Rmin {
				Rmin=buff;
			} Rmin=buff Rmin buff System.out.println(Math.max(0, Rmin-Lmax+1)) System.out.println System.out System System.out Math.max(0, Rmin-Lmax+1) Math.max Math 0 Rmin-Lmax+1 Rmin-Lmax Rmin Lmax 1 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 Rmin=1000000,Lmax=0,buff;
		for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		}
		System.out.println(Math.max(0, Rmin-Lmax+1));

	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int Rmin=1000000,Lmax=0,buff;
		for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		}
		System.out.println(Math.max(0, Rmin-Lmax+1));

	}
} 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 Rmin=1000000,Lmax=0,buff;
		for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		}
		System.out.println(Math.max(0, Rmin-Lmax+1));

	}
}


