import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int maxL = 0;
		int minR = 100001;
		for(int i=0; i<M; i++) {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		}
		sc.close();

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

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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int maxL = 0;
		int minR = 100001;
		for(int i=0; i<M; i++) {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		}
		sc.close();

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

} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int maxL = 0;
		int minR = 100001;
		for(int i=0; i<M; i++) {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		}
		sc.close();

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

		Scanner sc = new Scanner(System.in);
		Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int maxL = 0;
		int minR = 100001;
		for(int i=0; i<M; i++) {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		}
		sc.close();

		System.out.println(Math.max(0, minR-maxL+1));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int M = Integer.parseInt(sc.next()); M Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int maxL = 0; maxL 0 int minR = 100001; minR 100001 for(int i=0; i<M; i++) {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		} {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		} maxL = Math.max(maxL, Integer.parseInt(sc.next())) maxL Math.max(maxL, Integer.parseInt(sc.next())) Math.max Math maxL Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc minR = Math.min(minR, Integer.parseInt(sc.next())) minR Math.min(minR, Integer.parseInt(sc.next())) Math.min Math minR Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc System.out.println(Math.max(0, minR-maxL+1)) System.out.println System.out System System.out Math.max(0, minR-maxL+1) Math.max Math 0 minR-maxL+1 minR-maxL minR maxL 1 String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int maxL = 0;
		int minR = 100001;
		for(int i=0; i<M; i++) {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		}
		sc.close();

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

} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int maxL = 0;
		int minR = 100001;
		for(int i=0; i<M; i++) {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		}
		sc.close();

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

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int maxL = 0;
		int minR = 100001;
		for(int i=0; i<M; i++) {
			maxL = Math.max(maxL, Integer.parseInt(sc.next()));
			minR = Math.min(minR, Integer.parseInt(sc.next()));
		}
		sc.close();

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

}
