import java.util.ArrayList;
		import java.util.Collection;
		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);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Integer> l = new ArrayList<>();
		List<Integer> r = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		}
		int min = Collections.max(l);
		int max = Collections.min(r);
		int num = Math.min(max, n) + 1 - Math.max(min, 1);
		if (num < 0) {
			num = 0;
		}
		System.out.println(num);
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Collection; Collection 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);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Integer> l = new ArrayList<>();
		List<Integer> r = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		}
		int min = Collections.max(l);
		int max = Collections.min(r);
		int num = Math.min(max, n) + 1 - Math.max(min, 1);
		if (num < 0) {
			num = 0;
		}
		System.out.println(num);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Integer> l = new ArrayList<>();
		List<Integer> r = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		}
		int min = Collections.max(l);
		int max = Collections.min(r);
		int num = Math.min(max, n) + 1 - Math.max(min, 1);
		if (num < 0) {
			num = 0;
		}
		System.out.println(num);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Integer> l = new ArrayList<>();
		List<Integer> r = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		}
		int min = Collections.max(l);
		int max = Collections.min(r);
		int num = Math.min(max, n) + 1 - Math.max(min, 1);
		if (num < 0) {
			num = 0;
		}
		System.out.println(num);
	} 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 List<Integer> l = new ArrayList<>(); l new ArrayList<>() List<Integer> r = new ArrayList<>(); r new ArrayList<>() for (int i = 0; i < m; i++) {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		} {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		} l.add(sc.nextInt()) l.add l sc.nextInt() sc.nextInt sc r.add(sc.nextInt()) r.add r sc.nextInt() sc.nextInt sc int min = Collections.max(l); min Collections.max(l) Collections.max Collections l int max = Collections.min(r); max Collections.min(r) Collections.min Collections r int num = Math.min(max, n) + 1 - Math.max(min, 1); num Math.min(max, n) + 1 - Math.max(min, 1) Math.min(max, n) + 1 Math.min(max, n) Math.min Math max n 1 Math.max(min, 1) Math.max Math min 1 if (num < 0) {
			num = 0;
		} num < 0 num 0 {
			num = 0;
		} num = 0 num 0 System.out.println(num) System.out.println System.out System System.out num 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();
		List<Integer> l = new ArrayList<>();
		List<Integer> r = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		}
		int min = Collections.max(l);
		int max = Collections.min(r);
		int num = Math.min(max, n) + 1 - Math.max(min, 1);
		if (num < 0) {
			num = 0;
		}
		System.out.println(num);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Integer> l = new ArrayList<>();
		List<Integer> r = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		}
		int min = Collections.max(l);
		int max = Collections.min(r);
		int num = Math.min(max, n) + 1 - Math.max(min, 1);
		if (num < 0) {
			num = 0;
		}
		System.out.println(num);
	}
} Main
import java.util.ArrayList;
		import java.util.Collection;
		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);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Integer> l = new ArrayList<>();
		List<Integer> r = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			l.add(sc.nextInt());
			r.add(sc.nextInt());
		}
		int min = Collections.max(l);
		int max = Collections.min(r);
		int num = Math.min(max, n) + 1 - Math.max(min, 1);
		if (num < 0) {
			num = 0;
		}
		System.out.println(num);
	}
}
