
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 l = 1;
		int r = n;
		for (int i=0;i<m;i++) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		}

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

		System.out.println(Math.max(r-l+1, 0));

	}




} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

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

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

		System.out.println(Math.max(r-l+1, 0));

	} main {
		Scanner sc = new Scanner(System.in);

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

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

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

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

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

		System.out.println(Math.max(r-l+1, 0));

	}




}
