import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		}
		 catch (Exception e) {
			// TODO: handle exception
		}

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		}
		 catch (Exception e) {
			// TODO: handle exception
		}

	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		}
		 catch (Exception e) {
			// TODO: handle exception
		}

	} main {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		}
		 catch (Exception e) {
			// TODO: handle exception
		}

	} try (Scanner sc = new Scanner(System.in)) {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		}
		 catch (Exception e) {
			// TODO: handle exception
		} catch (Exception e) {
			// TODO: handle exception
		} Exception e {
			// TODO: handle exception
		} {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int N N M; M N = Integer.parseInt(sc.next()) N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc M = Integer.parseInt(sc.next()) M Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int iniMax = 0 iniMax 0 endMin = N; endMin N for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			} {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			} int ini = Integer.parseInt(sc.next()); ini Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int end = Integer.parseInt(sc.next()); end Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc iniMax = Math.max(iniMax, ini) iniMax Math.max(iniMax, ini) Math.max Math iniMax ini endMin = Math.min(endMin, end) endMin Math.min(endMin, end) Math.min Math endMin end int ans = endMin - iniMax + 1; ans endMin - iniMax + 1 endMin - iniMax endMin iniMax 1 if (ans > 0) System.out.println(ans);
			else System.out.println("0"); ans > 0 ans 0 System.out.println(ans) System.out.println System.out System System.out ans 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) {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		}
		 catch (Exception e) {
			// TODO: handle exception
		}

	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		}
		 catch (Exception e) {
			// TODO: handle exception
		}

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int N, M;
			N = Integer.parseInt(sc.next());
			M = Integer.parseInt(sc.next());

			int iniMax = 0, endMin = N;

			for (int i = 0; i < M; i++) {
				int ini = Integer.parseInt(sc.next());
				int end = Integer.parseInt(sc.next());
				
				iniMax = Math.max(iniMax, ini);
				endMin = Math.min(endMin, end);
			}
			int ans = endMin - iniMax + 1;
			if (ans > 0) System.out.println(ans);
			else System.out.println("0");		}
		 catch (Exception e) {
			// TODO: handle exception
		}

	}

}
