import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		int max = n;
		int min = 0;
		int l;
		int r;
		for(;0<m;m--) {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		}
		if(max-min<0) {
			System.out.println(0);
		}else {
			System.out.println(max-min + 1);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		int max = n;
		int min = 0;
		int l;
		int r;
		for(;0<m;m--) {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		}
		if(max-min<0) {
			System.out.println(0);
		}else {
			System.out.println(max-min + 1);
		}
	}
} Main public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		int max = n;
		int min = 0;
		int l;
		int r;
		for(;0<m;m--) {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		}
		if(max-min<0) {
			System.out.println(0);
		}else {
			System.out.println(max-min + 1);
		}
	} main {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		int max = n;
		int min = 0;
		int l;
		int r;
		for(;0<m;m--) {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		}
		if(max-min<0) {
			System.out.println(0);
		}else {
			System.out.println(max-min + 1);
		}
	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int n = scn.nextInt(); n scn.nextInt() scn.nextInt scn int m = scn.nextInt(); m scn.nextInt() scn.nextInt scn int max = n; max n int min = 0; min 0 int l; l int r; r for(;0<m;m--) {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		} ; 0<m 0 m m-- m-- m {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		} {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		} l = scn.nextInt() l scn.nextInt() scn.nextInt scn r = scn.nextInt() r scn.nextInt() scn.nextInt scn if(min<l) {
				min = l;
			} min<l min l {
				min = l;
			} min = l min l if(r<max) {
				max = r;
			} r<max r max {
				max = r;
			} max = r max r if(max-min<0) {
			System.out.println(0);
		}else {
			System.out.println(max-min + 1);
		} max-min<0 max-min max min 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(max-min + 1);
		} System.out.println(max-min + 1) System.out.println System.out System System.out max-min + 1 max-min max min 1 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		int max = n;
		int min = 0;
		int l;
		int r;
		for(;0<m;m--) {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		}
		if(max-min<0) {
			System.out.println(0);
		}else {
			System.out.println(max-min + 1);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		int max = n;
		int min = 0;
		int l;
		int r;
		for(;0<m;m--) {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		}
		if(max-min<0) {
			System.out.println(0);
		}else {
			System.out.println(max-min + 1);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		int max = n;
		int min = 0;
		int l;
		int r;
		for(;0<m;m--) {
			l = scn.nextInt();
			r = scn.nextInt();
			if(min<l) {
				min = l;
			}
			if(r<max) {
				max = r;
			}
		}
		if(max-min<0) {
			System.out.println(0);
		}else {
			System.out.println(max-min + 1);
		}
	}
}