import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		List<Long> l = new ArrayList<>(), r = new ArrayList<>();
		for(int i = 0; i < M; i++) {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		}
		Collections.sort(l);
		Collections.sort(r);
		
		Long left = l.get(l.size()-1);
		Long right = r.get(0);
		
		Long ans = right-left+1;
		if(right >= left)System.out.println(ans);
		else System.out.println(0);
		
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		List<Long> l = new ArrayList<>(), r = new ArrayList<>();
		for(int i = 0; i < M; i++) {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		}
		Collections.sort(l);
		Collections.sort(r);
		
		Long left = l.get(l.size()-1);
		Long right = r.get(0);
		
		Long ans = right-left+1;
		if(right >= left)System.out.println(ans);
		else System.out.println(0);
		
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		List<Long> l = new ArrayList<>(), r = new ArrayList<>();
		for(int i = 0; i < M; i++) {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		}
		Collections.sort(l);
		Collections.sort(r);
		
		Long left = l.get(l.size()-1);
		Long right = r.get(0);
		
		Long ans = right-left+1;
		if(right >= left)System.out.println(ans);
		else System.out.println(0);
		
	} main {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		List<Long> l = new ArrayList<>(), r = new ArrayList<>();
		for(int i = 0; i < M; i++) {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		}
		Collections.sort(l);
		Collections.sort(r);
		
		Long left = l.get(l.size()-1);
		Long right = r.get(0);
		
		Long ans = right-left+1;
		if(right >= left)System.out.println(ans);
		else System.out.println(0);
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long N = sc.nextLong() N sc.nextLong() sc.nextLong sc M = sc.nextLong(); M sc.nextLong() sc.nextLong sc List<Long> l = new ArrayList<>() l new ArrayList<>() r = new ArrayList<>(); r new ArrayList<>() for(int i = 0; i < M; i++) {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		} {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		} l.add(sc.nextLong()) l.add l sc.nextLong() sc.nextLong sc r.add(sc.nextLong()) r.add r sc.nextLong() sc.nextLong sc Collections.sort(l) Collections.sort Collections l Collections.sort(r) Collections.sort Collections r Long left = l.get(l.size()-1); left l.get(l.size()-1) l.get l l.size()-1 l.size() l.size l 1 Long right = r.get(0); right r.get(0) r.get r 0 Long ans = right-left+1; ans right-left+1 right-left right left 1 if(right >= left)System.out.println(ans);
		else System.out.println(0); right >= left right left System.out.println(ans) System.out.println System.out System System.out ans System.out.println(0) System.out.println System.out System System.out 0 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		List<Long> l = new ArrayList<>(), r = new ArrayList<>();
		for(int i = 0; i < M; i++) {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		}
		Collections.sort(l);
		Collections.sort(r);
		
		Long left = l.get(l.size()-1);
		Long right = r.get(0);
		
		Long ans = right-left+1;
		if(right >= left)System.out.println(ans);
		else System.out.println(0);
		
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		List<Long> l = new ArrayList<>(), r = new ArrayList<>();
		for(int i = 0; i < M; i++) {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		}
		Collections.sort(l);
		Collections.sort(r);
		
		Long left = l.get(l.size()-1);
		Long right = r.get(0);
		
		Long ans = right-left+1;
		if(right >= left)System.out.println(ans);
		else System.out.println(0);
		
	}
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), M = sc.nextLong();
		List<Long> l = new ArrayList<>(), r = new ArrayList<>();
		for(int i = 0; i < M; i++) {
			l.add(sc.nextLong());
			r.add(sc.nextLong());
		}
		Collections.sort(l);
		Collections.sort(r);
		
		Long left = l.get(l.size()-1);
		Long right = r.get(0);
		
		Long ans = right-left+1;
		if(right >= left)System.out.println(ans);
		else System.out.println(0);
		
	}
}