import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int max_L = 0;
		int min_R = N;

		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		}

		int ans = min_R - max_L + 1;
		if(ans > 0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int max_L = 0;
		int min_R = N;

		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		}

		int ans = min_R - max_L + 1;
		if(ans > 0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	}
} Main public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int max_L = 0;
		int min_R = N;

		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		}

		int ans = min_R - max_L + 1;
		if(ans > 0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int max_L = 0;
		int min_R = N;

		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		}

		int ans = min_R - max_L + 1;
		if(ans > 0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int max_L = 0; max_L 0 int min_R = N; min_R N for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		} {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		} int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc if(max_L <= L) {
				max_L = L;
			} max_L <= L max_L L {
				max_L = L;
			} max_L = L max_L L if(R <= min_R) {
				min_R = R;
			} R <= min_R R min_R {
				min_R = R;
			} min_R = R min_R R int ans = min_R - max_L + 1; ans min_R - max_L + 1 min_R - max_L min_R max_L 1 if(ans > 0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		} ans > 0 ans 0 {
			System.out.println(ans);
		} System.out.println(ans) System.out.println System.out System System.out ans {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 String args[] args public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int max_L = 0;
		int min_R = N;

		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		}

		int ans = min_R - max_L + 1;
		if(ans > 0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	}
} public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int max_L = 0;
		int min_R = N;

		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		}

		int ans = min_R - max_L + 1;
		if(ans > 0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int max_L = 0;
		int min_R = N;

		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();

			if(max_L <= L) {
				max_L = L;
			}

			if(R <= min_R) {
				min_R = R;
			}
		}

		int ans = min_R - max_L + 1;
		if(ans > 0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	}
}
