import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}

		int ans = Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1;

		System.out.println(Math.max(ans, 0));

	}

} import java.util.Arrays; Arrays 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 = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}

		int ans = Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1;

		System.out.println(Math.max(ans, 0));

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}

		int ans = Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1;

		System.out.println(Math.max(ans, 0));

	} main {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}

		int ans = Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1;

		System.out.println(Math.max(ans, 0));

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] l = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m for (int i = 0; i < m; i++) {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		} {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		} l[i] = Integer.parseInt(sc.next()) l[i] l i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r[i] = Integer.parseInt(sc.next()) r[i] r i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int ans = Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1; ans Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1 Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() Arrays.stream(r).min().getAsInt() Arrays.stream(r).min().getAsInt Arrays.stream(r).min() Arrays.stream(r).min Arrays.stream(r) Arrays.stream Arrays r Arrays.stream(l).max().getAsInt() Arrays.stream(l).max().getAsInt Arrays.stream(l).max() Arrays.stream(l).max Arrays.stream(l) Arrays.stream Arrays l 1 System.out.println(Math.max(ans, 0)) System.out.println System.out System System.out Math.max(ans, 0) Math.max Math ans 0 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}

		int ans = Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1;

		System.out.println(Math.max(ans, 0));

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}

		int ans = Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1;

		System.out.println(Math.max(ans, 0));

	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = Integer.parseInt(sc.next());
			r[i] = Integer.parseInt(sc.next());
		}

		int ans = Arrays.stream(r).min().getAsInt() - Arrays.stream(l).max().getAsInt() + 1;

		System.out.println(Math.max(ans, 0));

	}

}
