import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		}
	}
} Main public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		}
	} main {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		}
	} try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		} {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		} Scanner s = new Scanner(System.in) Scanner s = new Scanner(System.in) new Scanner(System.in) final int n = s.nextInt(); n s.nextInt() s.nextInt s final int m = s.nextInt(); m s.nextInt() s.nextInt s int maxStart = 0; maxStart 0 int minEnd = n; minEnd n for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			} {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			} int start = s.nextInt(); start s.nextInt() s.nextInt s int end = s.nextInt(); end s.nextInt() s.nextInt s if (start > maxStart) {
					maxStart = start;
				} start > maxStart start maxStart {
					maxStart = start;
				} maxStart = start maxStart start if (end < minEnd) {
					minEnd = end;
				} end < minEnd end minEnd {
					minEnd = end;
				} minEnd = end minEnd end if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			} minEnd < maxStart minEnd maxStart {
				System.out.println(0);
			} System.out.println(0) System.out.println System.out System System.out 0 {
				System.out.println(minEnd - maxStart + 1);
			} System.out.println(minEnd - maxStart + 1) System.out.println System.out System System.out minEnd - maxStart + 1 minEnd - maxStart minEnd maxStart 1 String[] args args public class Main {

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		}
	}
} public class Main {

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int n = s.nextInt();
			final int m = s.nextInt();

			int maxStart = 0;
			int minEnd = n;

			for (int i = 0; i < m; i++) {
				int start = s.nextInt();
				int end = s.nextInt();
				if (start > maxStart) {
					maxStart = start;
				}
				if (end < minEnd) {
					minEnd = end;
				}
			}
			if (minEnd < maxStart) {
				System.out.println(0);
			} else {
				System.out.println(minEnd - maxStart + 1);
			}
		}
	}
}