
import java.util.Scanner;

public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		sc.nextInt();
		int M = sc.nextInt();

		int min = Integer.MIN_VALUE;
		int max = Integer.MAX_VALUE;

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

		System.out.println(min <= max ? max - min + 1 : 0);

	}
} import java.util.Scanner; Scanner java.util public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		sc.nextInt();
		int M = sc.nextInt();

		int min = Integer.MIN_VALUE;
		int max = Integer.MAX_VALUE;

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

		System.out.println(min <= max ? max - min + 1 : 0);

	}
} Main private static Scanner sc; sc public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		sc.nextInt();
		int M = sc.nextInt();

		int min = Integer.MIN_VALUE;
		int max = Integer.MAX_VALUE;

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

		System.out.println(min <= max ? max - min + 1 : 0);

	} main {
		sc = new Scanner(System.in);
		sc.nextInt();
		int M = sc.nextInt();

		int min = Integer.MIN_VALUE;
		int max = Integer.MAX_VALUE;

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

		System.out.println(min <= max ? max - min + 1 : 0);

	} sc = new Scanner(System.in) sc new Scanner(System.in) sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int min = Integer.MIN_VALUE; min Integer.MIN_VALUE Integer Integer.MIN_VALUE int max = Integer.MAX_VALUE; max Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < M; i++) {
			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		} {
			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		} min = Math.max(min, sc.nextInt()) min Math.max(min, sc.nextInt()) Math.max Math min sc.nextInt() sc.nextInt sc max = Math.min(max, sc.nextInt()) max Math.min(max, sc.nextInt()) Math.min Math max sc.nextInt() sc.nextInt sc System.out.println(min <= max ? max - min + 1 : 0) System.out.println System.out System System.out min <= max ? max - min + 1 : 0 min <= max min max max - min + 1 max - min max min 1 0 String[] args args public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		sc.nextInt();
		int M = sc.nextInt();

		int min = Integer.MIN_VALUE;
		int max = Integer.MAX_VALUE;

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

		System.out.println(min <= max ? max - min + 1 : 0);

	}
} public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		sc.nextInt();
		int M = sc.nextInt();

		int min = Integer.MIN_VALUE;
		int max = Integer.MAX_VALUE;

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

		System.out.println(min <= max ? max - min + 1 : 0);

	}
} Main

import java.util.Scanner;

public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		sc.nextInt();
		int M = sc.nextInt();

		int min = Integer.MIN_VALUE;
		int max = Integer.MAX_VALUE;

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

		System.out.println(min <= max ? max - min + 1 : 0);

	}
}