import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ansL = 1;
		int ansR = sc.nextInt();
		int M = sc.nextInt();
		for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(0,ansR-ansL+1));
	}
};
 import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ansL = 1;
		int ansR = sc.nextInt();
		int M = sc.nextInt();
		for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(0,ansR-ansL+1));
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ansL = 1;
		int ansR = sc.nextInt();
		int M = sc.nextInt();
		for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(0,ansR-ansL+1));
	} main {
		Scanner sc = new Scanner(System.in);
		int ansL = 1;
		int ansR = sc.nextInt();
		int M = sc.nextInt();
		for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(0,ansR-ansL+1));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int ansL = 1; ansL 1 int ansR = sc.nextInt(); ansR sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		} {
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		} ansL = Math.max(ansL,sc.nextInt()) ansL Math.max(ansL,sc.nextInt()) Math.max Math ansL sc.nextInt() sc.nextInt sc ansR = Math.min(ansR,sc.nextInt()) ansR Math.min(ansR,sc.nextInt()) Math.min Math ansR sc.nextInt() sc.nextInt sc sc.close() sc.close sc System.out.println(Math.max(0,ansR-ansL+1)) System.out.println System.out System System.out Math.max(0,ansR-ansL+1) Math.max Math 0 ansR-ansL+1 ansR-ansL ansR ansL 1 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ansL = 1;
		int ansR = sc.nextInt();
		int M = sc.nextInt();
		for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(0,ansR-ansL+1));
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ansL = 1;
		int ansR = sc.nextInt();
		int M = sc.nextInt();
		for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(0,ansR-ansL+1));
	}
} Main
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ansL = 1;
		int ansR = sc.nextInt();
		int M = sc.nextInt();
		for(int i = 0; i < M ; i++){
			ansL = Math.max(ansL,sc.nextInt());
			ansR = Math.min(ansR,sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(0,ansR-ansL+1));
	}
};

