import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		int lmax = 0;
		int rmin = n;
		// カードの枚数は、Lの最大値以上Rの最小値以下
		for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		}
		
		System.out.println(Math.max(rmin + 1 - lmax, 0));
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		int lmax = 0;
		int rmin = n;
		// カードの枚数は、Lの最大値以上Rの最小値以下
		for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		}
		
		System.out.println(Math.max(rmin + 1 - lmax, 0));
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		int lmax = 0;
		int rmin = n;
		// カードの枚数は、Lの最大値以上Rの最小値以下
		for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		}
		
		System.out.println(Math.max(rmin + 1 - lmax, 0));
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		int lmax = 0;
		int rmin = n;
		// カードの枚数は、Lの最大値以上Rの最小値以下
		for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		}
		
		System.out.println(Math.max(rmin + 1 - lmax, 0));
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int m = scanner.nextInt(); m scanner.nextInt() scanner.nextInt scanner int lmax = 0; lmax 0 int rmin = n; rmin n for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		} {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		} lmax = Math.max(lmax, scanner.nextInt()) lmax Math.max(lmax, scanner.nextInt()) Math.max Math lmax scanner.nextInt() scanner.nextInt scanner rmin = Math.min(rmin, scanner.nextInt()) rmin Math.min(rmin, scanner.nextInt()) Math.min Math rmin scanner.nextInt() scanner.nextInt scanner System.out.println(Math.max(rmin + 1 - lmax, 0)) System.out.println System.out System System.out Math.max(rmin + 1 - lmax, 0) Math.max Math rmin + 1 - lmax rmin + 1 rmin 1 lmax 0 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		int lmax = 0;
		int rmin = n;
		// カードの枚数は、Lの最大値以上Rの最小値以下
		for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		}
		
		System.out.println(Math.max(rmin + 1 - lmax, 0));
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		int lmax = 0;
		int rmin = n;
		// カードの枚数は、Lの最大値以上Rの最小値以下
		for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		}
		
		System.out.println(Math.max(rmin + 1 - lmax, 0));
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		int lmax = 0;
		int rmin = n;
		// カードの枚数は、Lの最大値以上Rの最小値以下
		for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		}
		
		System.out.println(Math.max(rmin + 1 - lmax, 0));
	}
}
