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();
		int[] l = new int[m];
		int[] r = new int[m];
		int start = 0;
		int end = 0;
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		}
		if (start > end) {
			System.out.println(0);
		} else {
			System.out.println(end - start + 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 = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		int start = 0;
		int end = 0;
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		}
		if (start > end) {
			System.out.println(0);
		} else {
			System.out.println(end - start + 1);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		int start = 0;
		int end = 0;
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		}
		if (start > end) {
			System.out.println(0);
		} else {
			System.out.println(end - start + 1);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		int start = 0;
		int end = 0;
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		}
		if (start > end) {
			System.out.println(0);
		} else {
			System.out.println(end - start + 1);
		}
	} 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[] l = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m int start = 0; start 0 int end = 0; end 0 for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		} {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		} l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			} i == 0 i 0 {
				start = l[i];
				end = r[i];
			} start = l[i] start l[i] l i end = r[i] end r[i] r i {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			} if (l[i] > start) {
					start = l[i];
				} l[i] > start l[i] l i start {
					start = l[i];
				} start = l[i] start l[i] l i if (r[i] < end) {
					end = r[i];
				} r[i] < end r[i] r i end {
					end = r[i];
				} end = r[i] end r[i] r i if (start > end) {
			System.out.println(0);
		} else {
			System.out.println(end - start + 1);
		} start > end start end {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(end - start + 1);
		} System.out.println(end - start + 1) System.out.println System.out System System.out end - start + 1 end - start end start 1 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();
		int[] l = new int[m];
		int[] r = new int[m];
		int start = 0;
		int end = 0;
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		}
		if (start > end) {
			System.out.println(0);
		} else {
			System.out.println(end - start + 1);
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		int start = 0;
		int end = 0;
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		}
		if (start > end) {
			System.out.println(0);
		} else {
			System.out.println(end - start + 1);
		}
	}
} Main
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();
		int[] l = new int[m];
		int[] r = new int[m];
		int start = 0;
		int end = 0;
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			if (i == 0) {
				start = l[i];
				end = r[i];
			} else {
				if (l[i] > start) {
					start = l[i];
				}
				if (r[i] < end) {
					end = r[i];
				}
			}
		}
		if (start > end) {
			System.out.println(0);
		} else {
			System.out.println(end - start + 1);
		}
	}
}
