import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int min = 0;
		int max = 100001;

		for(int i = 0; i < m; i++) {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		}

		System.out.println(Math.max(max - min + 1, 0));
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int min = 0;
		int max = 100001;

		for(int i = 0; i < m; i++) {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		}

		System.out.println(Math.max(max - min + 1, 0));
	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int min = 0;
		int max = 100001;

		for(int i = 0; i < m; i++) {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		}

		System.out.println(Math.max(max - min + 1, 0));
	} main {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int min = 0;
		int max = 100001;

		for(int i = 0; i < m; i++) {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		}

		System.out.println(Math.max(max - min + 1, 0));
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan int min = 0; min 0 int max = 100001; max 100001 for(int i = 0; i < m; i++) {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		} {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		} min = Math.max(min, scan.nextInt()) min Math.max(min, scan.nextInt()) Math.max Math min scan.nextInt() scan.nextInt scan max = Math.min(max, scan.nextInt()) max Math.min(max, scan.nextInt()) Math.min Math max scan.nextInt() scan.nextInt scan System.out.println(Math.max(max - min + 1, 0)) System.out.println System.out System System.out Math.max(max - min + 1, 0) Math.max Math max - min + 1 max - min max min 1 0 String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int min = 0;
		int max = 100001;

		for(int i = 0; i < m; i++) {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		}

		System.out.println(Math.max(max - min + 1, 0));
	}
} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int min = 0;
		int max = 100001;

		for(int i = 0; i < m; i++) {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		}

		System.out.println(Math.max(max - min + 1, 0));
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int m = scan.nextInt();
		int min = 0;
		int max = 100001;

		for(int i = 0; i < m; i++) {
			min = Math.max(min, scan.nextInt());
			max = Math.min(max, scan.nextInt());
		}

		System.out.println(Math.max(max - min + 1, 0));
	}
}