import java.util.Scanner;

class Main {

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

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

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

	int l = L[0];
	int r = R[0];
	for (int i = 1; i < M; i++) {
	    if (l < L[i])
		l = L[i];
	    if (r > R[i])
		r = R[i];
	}

	if (r - l < 0)
	    System.out.println(0);
	else
	    System.out.println(r - l + 1);
    }
} import java.util.Scanner; Scanner java.util class Main {

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

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

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

	int l = L[0];
	int r = R[0];
	for (int i = 1; i < M; i++) {
	    if (l < L[i])
		l = L[i];
	    if (r > R[i])
		r = R[i];
	}

	if (r - l < 0)
	    System.out.println(0);
	else
	    System.out.println(r - l + 1);
    }
} Main public static void main(String[] args)  {
	Scanner sc = new Scanner(System.in);

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

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

	int l = L[0];
	int r = R[0];
	for (int i = 1; i < M; i++) {
	    if (l < L[i])
		l = L[i];
	    if (r > R[i])
		r = R[i];
	}

	if (r - l < 0)
	    System.out.println(0);
	else
	    System.out.println(r - l + 1);
    } main {
	Scanner sc = new Scanner(System.in);

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

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

	int l = L[0];
	int r = R[0];
	for (int i = 1; i < M; i++) {
	    if (l < L[i])
		l = L[i];
	    if (r > R[i])
		r = R[i];
	}

	if (r - l < 0)
	    System.out.println(0);
	else
	    System.out.println(r - l + 1);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N N M; M N = sc.nextInt() N sc.nextInt() sc.nextInt sc M = sc.nextInt() M sc.nextInt() sc.nextInt sc int L[] = new int[M]; L new int[M] M int R[] = new int[M]; R new int[M] M for (int i = 0; i < M; i++) {
	    L[i] = sc.nextInt();
	    R[i] = sc.nextInt();
	} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
	    L[i] = sc.nextInt();
	    R[i] = sc.nextInt();
	} {
	    L[i] = sc.nextInt();
	    R[i] = sc.nextInt();
	} L[i] = sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc int l = L[0]; l L[0] L 0 int r = R[0]; r R[0] R 0 for (int i = 1; i < M; i++) {
	    if (l < L[i])
		l = L[i];
	    if (r > R[i])
		r = R[i];
	} int i = 1; int i = 1; i 1 i < M i M i++ i++ i {
	    if (l < L[i])
		l = L[i];
	    if (r > R[i])
		r = R[i];
	} {
	    if (l < L[i])
		l = L[i];
	    if (r > R[i])
		r = R[i];
	} if (l < L[i])
		l = L[i]; l < L[i] l L[i] L i l = L[i] l L[i] L i if (r > R[i])
		r = R[i]; r > R[i] r R[i] R i r = R[i] r R[i] R i if (r - l < 0)
	    System.out.println(0);
	else
	    System.out.println(r - l + 1); r - l < 0 r - l r l 0 System.out.println(0) System.out.println System.out System System.out 0 System.out.println(r - l + 1) System.out.println System.out System System.out r - l + 1 r - l r l 1 String[] args args
import java.util.Scanner;

class Main {

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

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

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

	int l = L[0];
	int r = R[0];
	for (int i = 1; i < M; i++) {
	    if (l < L[i])
		l = L[i];
	    if (r > R[i])
		r = R[i];
	}

	if (r - l < 0)
	    System.out.println(0);
	else
	    System.out.println(r - l + 1);
    }
}