import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l, r, tmpl, tmpr;
		l = sc.nextInt();
		r = sc.nextInt();
		boolean b = true;
		for (int i = 1; i < m; i++) {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		}
		if (r - l >= 0) {
			System.out.println(r - l + 1);
		} else {
			System.out.println(0);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l, r, tmpl, tmpr;
		l = sc.nextInt();
		r = sc.nextInt();
		boolean b = true;
		for (int i = 1; i < m; i++) {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		}
		if (r - l >= 0) {
			System.out.println(r - l + 1);
		} else {
			System.out.println(0);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l, r, tmpl, tmpr;
		l = sc.nextInt();
		r = sc.nextInt();
		boolean b = true;
		for (int i = 1; i < m; i++) {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		}
		if (r - l >= 0) {
			System.out.println(r - l + 1);
		} else {
			System.out.println(0);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l, r, tmpl, tmpr;
		l = sc.nextInt();
		r = sc.nextInt();
		boolean b = true;
		for (int i = 1; i < m; i++) {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		}
		if (r - l >= 0) {
			System.out.println(r - l + 1);
		} else {
			System.out.println(0);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int l l r r tmpl tmpl tmpr; tmpr l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt() r sc.nextInt() sc.nextInt sc boolean b = true; b true for (int i = 1; i < m; i++) {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		} int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		} {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		} tmpl = sc.nextInt() tmpl sc.nextInt() sc.nextInt sc tmpr = sc.nextInt() tmpr sc.nextInt() sc.nextInt sc if (l <= tmpl) {
				l = tmpl;
			} l <= tmpl l tmpl {
				l = tmpl;
			} l = tmpl l tmpl if (r >= tmpr) {
				r = tmpr;
			} r >= tmpr r tmpr {
				r = tmpr;
			} r = tmpr r tmpr if (r - l >= 0) {
			System.out.println(r - l + 1);
		} else {
			System.out.println(0);
		} r - l >= 0 r - l r l 0 {
			System.out.println(r - l + 1);
		} System.out.println(r - l + 1) System.out.println System.out System System.out r - l + 1 r - l r l 1 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l, r, tmpl, tmpr;
		l = sc.nextInt();
		r = sc.nextInt();
		boolean b = true;
		for (int i = 1; i < m; i++) {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		}
		if (r - l >= 0) {
			System.out.println(r - l + 1);
		} else {
			System.out.println(0);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l, r, tmpl, tmpr;
		l = sc.nextInt();
		r = sc.nextInt();
		boolean b = true;
		for (int i = 1; i < m; i++) {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		}
		if (r - l >= 0) {
			System.out.println(r - l + 1);
		} else {
			System.out.println(0);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l, r, tmpl, tmpr;
		l = sc.nextInt();
		r = sc.nextInt();
		boolean b = true;
		for (int i = 1; i < m; i++) {
			tmpl = sc.nextInt();
			tmpr = sc.nextInt();
			if (l <= tmpl) {
				l = tmpl;
			}
			if (r >= tmpr) {
				r = tmpr;
			}
		}
		if (r - l >= 0) {
			System.out.println(r - l + 1);
		} else {
			System.out.println(0);
		}
	}
}
