import 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();

		int maxL = 0;
		int minR = 0;
		for(int i=0; i<M; i++) {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		}

		int count = maxL>minR ? 0 : minR-maxL+1;
		println(count);
	}

	public static void println(Object o) {
		System.out.println(o);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int maxL = 0;
		int minR = 0;
		for(int i=0; i<M; i++) {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		}

		int count = maxL>minR ? 0 : minR-maxL+1;
		println(count);
	}

	public static void println(Object o) {
		System.out.println(o);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int maxL = 0;
		int minR = 0;
		for(int i=0; i<M; i++) {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		}

		int count = maxL>minR ? 0 : minR-maxL+1;
		println(count);
	} main {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int maxL = 0;
		int minR = 0;
		for(int i=0; i<M; i++) {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		}

		int count = maxL>minR ? 0 : minR-maxL+1;
		println(count);
	} 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 int maxL = 0; maxL 0 int minR = 0; minR 0 for(int i=0; i<M; i++) {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		} {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		} if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			} i == 0 i 0 {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} maxL = sc.nextInt() maxL sc.nextInt() sc.nextInt sc minR = sc.nextInt() minR sc.nextInt() sc.nextInt sc {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			} int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc maxL = maxL < L ? L : maxL maxL maxL < L ? L : maxL maxL < L maxL L L maxL minR = minR > R ? R : minR minR minR > R ? R : minR minR > R minR R R minR int count = maxL>minR ? 0 : minR-maxL+1; count maxL>minR ? 0 : minR-maxL+1 maxL>minR maxL minR 0 minR-maxL+1 minR-maxL minR maxL 1 println(count) println count String[] args args public static void println(Object o) {
		System.out.println(o);
	} println {
		System.out.println(o);
	} System.out.println(o) System.out.println System.out System System.out o Object o o public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int maxL = 0;
		int minR = 0;
		for(int i=0; i<M; i++) {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		}

		int count = maxL>minR ? 0 : minR-maxL+1;
		println(count);
	}

	public static void println(Object o) {
		System.out.println(o);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int maxL = 0;
		int minR = 0;
		for(int i=0; i<M; i++) {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		}

		int count = maxL>minR ? 0 : minR-maxL+1;
		println(count);
	}

	public static void println(Object o) {
		System.out.println(o);
	}
} Main
import 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();

		int maxL = 0;
		int minR = 0;
		for(int i=0; i<M; i++) {
			if(i == 0) {
				maxL = sc.nextInt();
				minR = sc.nextInt();
			} else {
				int L = sc.nextInt();
				int R = sc.nextInt();

				maxL = maxL < L ? L : maxL;
				minR = minR > R ? R : minR;
			}
		}

		int count = maxL>minR ? 0 : minR-maxL+1;
		println(count);
	}

	public static void println(Object o) {
		System.out.println(o);
	}
}