import java.util.Scanner;



public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}
}


class Solve{


	 public void solve() {
		 Scanner sc = new Scanner(System.in) ;
		 int N = sc.nextInt();
		 int M = sc.nextInt();
		 int L ;
		 int R ;
		 int res = 0;
		 int l = 1;
		 int r = 100000;
		 for(int i = 0;i<M;i++) {
			 L = sc.nextInt(); 
			 R = sc.nextInt(); 
			 if(L>=l) {
				 l=L;
			 }
			 if(R<=r) {
				 r=R;
			 }
		 }
		 if(l<=r) {
		 System.out.println(r-l+1);
		 }else {
			 System.out.println(0);
		 }
		 
		 }
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}
} Main public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	} main {

		Solve s= new Solve();
		s.solve();

	} Solve s= new Solve(); s new Solve() s.solve() s.solve s String[] args args class Solve{


	 public void solve() {
		 Scanner sc = new Scanner(System.in) ;
		 int N = sc.nextInt();
		 int M = sc.nextInt();
		 int L ;
		 int R ;
		 int res = 0;
		 int l = 1;
		 int r = 100000;
		 for(int i = 0;i<M;i++) {
			 L = sc.nextInt(); 
			 R = sc.nextInt(); 
			 if(L>=l) {
				 l=L;
			 }
			 if(R<=r) {
				 r=R;
			 }
		 }
		 if(l<=r) {
		 System.out.println(r-l+1);
		 }else {
			 System.out.println(0);
		 }
		 
		 }
} Solve public void solve() {
		 Scanner sc = new Scanner(System.in) ;
		 int N = sc.nextInt();
		 int M = sc.nextInt();
		 int L ;
		 int R ;
		 int res = 0;
		 int l = 1;
		 int r = 100000;
		 for(int i = 0;i<M;i++) {
			 L = sc.nextInt(); 
			 R = sc.nextInt(); 
			 if(L>=l) {
				 l=L;
			 }
			 if(R<=r) {
				 r=R;
			 }
		 }
		 if(l<=r) {
		 System.out.println(r-l+1);
		 }else {
			 System.out.println(0);
		 }
		 
		 } solve {
		 Scanner sc = new Scanner(System.in) ;
		 int N = sc.nextInt();
		 int M = sc.nextInt();
		 int L ;
		 int R ;
		 int res = 0;
		 int l = 1;
		 int r = 100000;
		 for(int i = 0;i<M;i++) {
			 L = sc.nextInt(); 
			 R = sc.nextInt(); 
			 if(L>=l) {
				 l=L;
			 }
			 if(R<=r) {
				 r=R;
			 }
		 }
		 if(l<=r) {
		 System.out.println(r-l+1);
		 }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 ; L int R ; R int res = 0; res 0 int l = 1; l 1 int r = 100000; r 100000 for(int i = 0;i<M;i++) {
			 L = sc.nextInt(); 
			 R = sc.nextInt(); 
			 if(L>=l) {
				 l=L;
			 }
			 if(R<=r) {
				 r=R;
			 }
		 } int i = 0; int i = 0; i 0 i<M i M i++ i++ i {
			 L = sc.nextInt(); 
			 R = sc.nextInt(); 
			 if(L>=l) {
				 l=L;
			 }
			 if(R<=r) {
				 r=R;
			 }
		 } {
			 L = sc.nextInt(); 
			 R = sc.nextInt(); 
			 if(L>=l) {
				 l=L;
			 }
			 if(R<=r) {
				 r=R;
			 }
		 } L = sc.nextInt() L sc.nextInt() sc.nextInt sc R = sc.nextInt() R sc.nextInt() sc.nextInt sc if(L>=l) {
				 l=L;
			 } L>=l L l {
				 l=L;
			 } l=L l L if(R<=r) {
				 r=R;
			 } R<=r R r {
				 r=R;
			 } r=R r R if(l<=r) {
		 System.out.println(r-l+1);
		 }else {
			 System.out.println(0);
		 } l<=r l r {
		 System.out.println(r-l+1);
		 } System.out.println(r-l+1) System.out.println System.out System System.out r-l+1 r-l r l 1 {
			 System.out.println(0);
		 } System.out.println(0) System.out.println System.out System System.out 0 public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}
} public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}
} Main
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}
}


class Solve{


	 public void solve() {
		 Scanner sc = new Scanner(System.in) ;
		 int N = sc.nextInt();
		 int M = sc.nextInt();
		 int L ;
		 int R ;
		 int res = 0;
		 int l = 1;
		 int r = 100000;
		 for(int i = 0;i<M;i++) {
			 L = sc.nextInt(); 
			 R = sc.nextInt(); 
			 if(L>=l) {
				 l=L;
			 }
			 if(R<=r) {
				 r=R;
			 }
		 }
		 if(l<=r) {
		 System.out.println(r-l+1);
		 }else {
			 System.out.println(0);
		 }
		 
		 }
}