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 = 0;
	int R = 0;
	int Lmax = 0;
	int Rmin = N;
	for(int i=0;i<M;i++){
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	}
	if(Lmax <= Rmin) System.out.print(Rmin -Lmax +1);
	else System.out.print(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 = 0;
	int R = 0;
	int Lmax = 0;
	int Rmin = N;
	for(int i=0;i<M;i++){
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	}
	if(Lmax <= Rmin) System.out.print(Rmin -Lmax +1);
	else System.out.print(0);
    }
} Main public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int M = sc.nextInt();

	int L = 0;
	int R = 0;
	int Lmax = 0;
	int Rmin = N;
	for(int i=0;i<M;i++){
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	}
	if(Lmax <= Rmin) System.out.print(Rmin -Lmax +1);
	else System.out.print(0);
    } main {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int M = sc.nextInt();

	int L = 0;
	int R = 0;
	int Lmax = 0;
	int Rmin = N;
	for(int i=0;i<M;i++){
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	}
	if(Lmax <= Rmin) System.out.print(Rmin -Lmax +1);
	else System.out.print(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 = 0; L 0 int R = 0; R 0 int Lmax = 0; Lmax 0 int Rmin = N; Rmin N for(int i=0;i<M;i++){
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	} int i=0; int i=0; i 0 i<M i M i++ i++ i {
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	} {
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	} L = sc.nextInt() L sc.nextInt() sc.nextInt sc R = sc.nextInt() R sc.nextInt() sc.nextInt sc if(L > Lmax) Lmax=L; L > Lmax L Lmax Lmax=L Lmax L if(R < Rmin) Rmin=R; R < Rmin R Rmin Rmin=R Rmin R if(Lmax <= Rmin) System.out.print(Rmin -Lmax +1);
	else System.out.print(0); Lmax <= Rmin Lmax Rmin System.out.print(Rmin -Lmax +1) System.out.print System.out System System.out Rmin -Lmax +1 Rmin -Lmax Rmin Lmax 1 System.out.print(0) System.out.print System.out System System.out 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 = 0;
	int R = 0;
	int Lmax = 0;
	int Rmin = N;
	for(int i=0;i<M;i++){
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	}
	if(Lmax <= Rmin) System.out.print(Rmin -Lmax +1);
	else System.out.print(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 = 0;
	int R = 0;
	int Lmax = 0;
	int Rmin = N;
	for(int i=0;i<M;i++){
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	}
	if(Lmax <= Rmin) System.out.print(Rmin -Lmax +1);
	else System.out.print(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 = 0;
	int R = 0;
	int Lmax = 0;
	int Rmin = N;
	for(int i=0;i<M;i++){
	    L = sc.nextInt();
	    R = sc.nextInt();
	    if(L > Lmax) Lmax=L;
	    if(R < Rmin) Rmin=R;
	}
	if(Lmax <= Rmin) System.out.print(Rmin -Lmax +1);
	else System.out.print(0);
    }
}
