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 maxLeft = 0;
		int minRight = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		}
		System.out.println(Math.max(0, minRight - maxLeft  + 1));

	}
} 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 maxLeft = 0;
		int minRight = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		}
		System.out.println(Math.max(0, minRight - maxLeft  + 1));

	}
} 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 maxLeft = 0;
		int minRight = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		}
		System.out.println(Math.max(0, minRight - maxLeft  + 1));

	} main {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int maxLeft = 0;
		int minRight = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		}
		System.out.println(Math.max(0, minRight - maxLeft  + 1));

	} 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 maxLeft = 0; maxLeft 0 int minRight = Integer.MAX_VALUE; minRight Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		} {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		} int left = Integer.parseInt(sc.next()); left Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int right = Integer.parseInt(sc.next()); right Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (left > maxLeft) {
				maxLeft = left;
			} left > maxLeft left maxLeft {
				maxLeft = left;
			} maxLeft = left maxLeft left if (right < minRight) {
				minRight = right;
			} right < minRight right minRight {
				minRight = right;
			} minRight = right minRight right System.out.println(Math.max(0, minRight - maxLeft  + 1)) System.out.println System.out System System.out Math.max(0, minRight - maxLeft  + 1) Math.max Math 0 minRight - maxLeft  + 1 minRight - maxLeft minRight maxLeft 1 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 maxLeft = 0;
		int minRight = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		}
		System.out.println(Math.max(0, minRight - maxLeft  + 1));

	}
} 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 maxLeft = 0;
		int minRight = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		}
		System.out.println(Math.max(0, minRight - maxLeft  + 1));

	}
} Main
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 maxLeft = 0;
		int minRight = Integer.MAX_VALUE;

		for (int i = 0; i < m; i++) {
			int left = Integer.parseInt(sc.next());
			int right = Integer.parseInt(sc.next());

			if (left > maxLeft) {
				maxLeft = left;
			}

			if (right < minRight) {
				minRight = right;
			}
		}
		System.out.println(Math.max(0, minRight - maxLeft  + 1));

	}
}