//package atCoder;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int numberOfGate = sc.nextInt();
		int LLimit = sc.nextInt();
		int RLimit = sc.nextInt();

		for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		}
		sc.close();

		System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int numberOfGate = sc.nextInt();
		int LLimit = sc.nextInt();
		int RLimit = sc.nextInt();

		for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		}
		sc.close();

		System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0);
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int numberOfGate = sc.nextInt();
		int LLimit = sc.nextInt();
		int RLimit = sc.nextInt();

		for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		}
		sc.close();

		System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0);
	} main {

		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int numberOfGate = sc.nextInt();
		int LLimit = sc.nextInt();
		int RLimit = sc.nextInt();

		for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		}
		sc.close();

		System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) sc.nextInt() sc.nextInt sc int numberOfGate = sc.nextInt(); numberOfGate sc.nextInt() sc.nextInt sc int LLimit = sc.nextInt(); LLimit sc.nextInt() sc.nextInt sc int RLimit = sc.nextInt(); RLimit sc.nextInt() sc.nextInt sc for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		} int i=1; int i=1; i 1 i<numberOfGate i numberOfGate i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc if(LLimit<l)
				LLimit = l; LLimit<l LLimit l LLimit = l LLimit l if(RLimit>r)
				RLimit = r; RLimit>r RLimit r RLimit = r RLimit r sc.close() sc.close sc System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0) System.out.println System.out System System.out RLimit-LLimit >=0?RLimit-LLimit+1:0 RLimit-LLimit >=0 RLimit-LLimit RLimit LLimit 0 RLimit-LLimit+1 RLimit-LLimit RLimit LLimit 1 0 String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int numberOfGate = sc.nextInt();
		int LLimit = sc.nextInt();
		int RLimit = sc.nextInt();

		for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		}
		sc.close();

		System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0);
	}
} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int numberOfGate = sc.nextInt();
		int LLimit = sc.nextInt();
		int RLimit = sc.nextInt();

		for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		}
		sc.close();

		System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0);
	}
} Main
//package atCoder;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		sc.nextInt();
		int numberOfGate = sc.nextInt();
		int LLimit = sc.nextInt();
		int RLimit = sc.nextInt();

		for(int i=1;i<numberOfGate;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			if(LLimit<l)
				LLimit = l;
			if(RLimit>r)
				RLimit = r;
		}
		sc.close();

		System.out.println(RLimit-LLimit >=0?RLimit-LLimit+1:0);
	}
}
