import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int N = 0;
		int M = 0;
		String s;
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		M = Integer.parseInt(sc.next());
		int i;
		int temp;
		int max = 100000, min = 0;
		for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		}
		int dif = max - min + 1;
		if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		}

	}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int N = 0;
		int M = 0;
		String s;
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		M = Integer.parseInt(sc.next());
		int i;
		int temp;
		int max = 100000, min = 0;
		for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		}
		int dif = max - min + 1;
		if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		}

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int N = 0;
		int M = 0;
		String s;
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		M = Integer.parseInt(sc.next());
		int i;
		int temp;
		int max = 100000, min = 0;
		for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		}
		int dif = max - min + 1;
		if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		}

	} main {
		// TODO 自動生成されたメソッド・スタブ
		int N = 0;
		int M = 0;
		String s;
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		M = Integer.parseInt(sc.next());
		int i;
		int temp;
		int max = 100000, min = 0;
		for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		}
		int dif = max - min + 1;
		if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		}

	} int N = 0; N 0 int M = 0; M 0 String s; s Scanner sc = new Scanner(System.in); sc new Scanner(System.in) N = Integer.parseInt(sc.next()) N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc M = Integer.parseInt(sc.next()) M Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int i; i int temp; temp int max = 100000 max 100000 min = 0; min 0 for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		} i = 0; i = 0 i 0 i < M i M i++ i++ i {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		} {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		} temp = Integer.parseInt(sc.next()) temp Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (min < temp) {
				min = temp;
			} min < temp min temp {
				min = temp;
			} min = temp min temp temp = Integer.parseInt(sc.next()) temp Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (max > temp) {
				max = temp;
			} max > temp max temp {
				max = temp;
			} max = temp max temp int dif = max - min + 1; dif max - min + 1 max - min max min 1 if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		} dif <= 0 dif 0 {
			System.out.println("0");
		} System.out.println("0") System.out.println System.out System System.out "0" if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		} dif <= N dif N {
			System.out.println(dif);
		} System.out.println(dif) System.out.println System.out System System.out dif {
			System.out.println(N);
		} System.out.println(N) System.out.println System.out System System.out N String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int N = 0;
		int M = 0;
		String s;
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		M = Integer.parseInt(sc.next());
		int i;
		int temp;
		int max = 100000, min = 0;
		for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		}
		int dif = max - min + 1;
		if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		}

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int N = 0;
		int M = 0;
		String s;
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		M = Integer.parseInt(sc.next());
		int i;
		int temp;
		int max = 100000, min = 0;
		for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		}
		int dif = max - min + 1;
		if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		}

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int N = 0;
		int M = 0;
		String s;
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		M = Integer.parseInt(sc.next());
		int i;
		int temp;
		int max = 100000, min = 0;
		for (i = 0; i < M; i++) {
			temp = Integer.parseInt(sc.next());
			if (min < temp) {
				min = temp;
			}
			temp = Integer.parseInt(sc.next());
			if (max > temp) {
				max = temp;
			}
		}
		int dif = max - min + 1;
		if (dif <= 0) {
			System.out.println("0");
		} else if (dif <= N) {
			System.out.println(dif);
		} else {
			System.out.println(N);
		}

	}

}