 

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

 class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in) ;
		int n = scan.nextInt();
		int m = scan.nextInt();
		ArrayList<Integer> L = new ArrayList<>();
		ArrayList<Integer> R = new ArrayList<>();
		for(int i = 0 ; i<m ; i++) {
			L.add(scan.nextInt());
			R.add(scan.nextInt());
		}
	    int a = Collections.max(L) ;
	    int b = Collections.min(R) ;
		int result = (b-a) +1 ;
		if(result > 0) {
			System.out.println(result);
		}else {
			System.out.println(0);
		}
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in) ;
		int n = scan.nextInt();
		int m = scan.nextInt();
		ArrayList<Integer> L = new ArrayList<>();
		ArrayList<Integer> R = new ArrayList<>();
		for(int i = 0 ; i<m ; i++) {
			L.add(scan.nextInt());
			R.add(scan.nextInt());
		}
	    int a = Collections.max(L) ;
	    int b = Collections.min(R) ;
		int result = (b-a) +1 ;
		if(result > 0) {
			System.out.println(result);
		}else {
			System.out.println(0);
		}
	}
} Main public static void main(String[]args) {
		Scanner scan = new Scanner(System.in) ;
		int n = scan.nextInt();
		int m = scan.nextInt();
		ArrayList<Integer> L = new ArrayList<>();
		ArrayList<Integer> R = new ArrayList<>();
		for(int i = 0 ; i<m ; i++) {
			L.add(scan.nextInt());
			R.add(scan.nextInt());
		}
	    int a = Collections.max(L) ;
	    int b = Collections.min(R) ;
		int result = (b-a) +1 ;
		if(result > 0) {
			System.out.println(result);
		}else {
			System.out.println(0);
		}
	} main {
		Scanner scan = new Scanner(System.in) ;
		int n = scan.nextInt();
		int m = scan.nextInt();
		ArrayList<Integer> L = new ArrayList<>();
		ArrayList<Integer> R = new ArrayList<>();
		for(int i = 0 ; i<m ; i++) {
			L.add(scan.nextInt());
			R.add(scan.nextInt());
		}
	    int a = Collections.max(L) ;
	    int b = Collections.min(R) ;
		int result = (b-a) +1 ;
		if(result > 0) {
			System.out.println(result);
		}else {
			System.out.println(0);
		}
	} Scanner scan = new Scanner(System.in) ; scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan ArrayList<Integer> L = new ArrayList<>(); L new ArrayList<>() ArrayList<Integer> R = new ArrayList<>(); R new ArrayList<>() for(int i = 0 ; i<m ; i++) {
			L.add(scan.nextInt());
			R.add(scan.nextInt());
		} int i = 0 ; int i = 0 ; i 0 i<m i m i++ i++ i {
			L.add(scan.nextInt());
			R.add(scan.nextInt());
		} {
			L.add(scan.nextInt());
			R.add(scan.nextInt());
		} L.add(scan.nextInt()) L.add L scan.nextInt() scan.nextInt scan R.add(scan.nextInt()) R.add R scan.nextInt() scan.nextInt scan int a = Collections.max(L) ; a Collections.max(L) Collections.max Collections L int b = Collections.min(R) ; b Collections.min(R) Collections.min Collections R int result = (b-a) +1 ; result (b-a) +1 (b-a) b a 1 if(result > 0) {
			System.out.println(result);
		}else {
			System.out.println(0);
		} result > 0 result 0 {
			System.out.println(result);
		} System.out.println(result) System.out.println System.out System System.out result {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 String[]args args
 

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

 class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in) ;
		int n = scan.nextInt();
		int m = scan.nextInt();
		ArrayList<Integer> L = new ArrayList<>();
		ArrayList<Integer> R = new ArrayList<>();
		for(int i = 0 ; i<m ; i++) {
			L.add(scan.nextInt());
			R.add(scan.nextInt());
		}
	    int a = Collections.max(L) ;
	    int b = Collections.min(R) ;
		int result = (b-a) +1 ;
		if(result > 0) {
			System.out.println(result);
		}else {
			System.out.println(0);
		}
	}
}
