

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int left = 1;
		int right = n;
		for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		}

		System.out.println(right - left + 1);
	}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int left = 1;
		int right = n;
		for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		}

		System.out.println(right - left + 1);
	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int left = 1;
		int right = n;
		for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		}

		System.out.println(right - left + 1);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int left = 1;
		int right = n;
		for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		}

		System.out.println(right - left + 1);
	} 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 left = 1; left 1 int right = n; right n for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc if(l > right || r < left){
				System.out.println(0);
				return;
			} l > right || r < left l > right l right r < left r left {
				System.out.println(0);
				return;
			} System.out.println(0) System.out.println System.out System System.out 0 return; left = Math.max(l, left) left Math.max(l, left) Math.max Math l left right = Math.min(r, right) right Math.min(r, right) Math.min Math r right System.out.println(right - left + 1) System.out.println System.out System System.out right - left + 1 right - left right left 1 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int left = 1;
		int right = n;
		for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		}

		System.out.println(right - left + 1);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int left = 1;
		int right = n;
		for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		}

		System.out.println(right - left + 1);
	}

} Main


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int left = 1;
		int right = n;
		for(int i = 0; i < m; i++){
			int l = sc.nextInt();
			int r = sc.nextInt();

			if(l > right || r < left){
				System.out.println(0);
				return;
			}

			left = Math.max(l, left);
			right = Math.min(r, right);
		}

		System.out.println(right - left + 1);
	}

}
