import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair{
		int L;
		int R;
		Pair(int L, int R){
			this.L=L;
			this.R=R;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Pair> lr = new ArrayList<>();
		for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		}

		int sum[] = new int[N+1];

		sum[0]=0;
		for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		}

		int cnt = 0;
		if(sum[N]==M) cnt++;
		for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair{
		int L;
		int R;
		Pair(int L, int R){
			this.L=L;
			this.R=R;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Pair> lr = new ArrayList<>();
		for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		}

		int sum[] = new int[N+1];

		sum[0]=0;
		for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		}

		int cnt = 0;
		if(sum[N]==M) cnt++;
		for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
} Main public static void main(String[] args) {
		Main main = new Main();
		main.run();
	} main {
		Main main = new Main();
		main.run();
	} Main main = new Main(); main new Main() main.run() main.run main String[] args args public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Pair> lr = new ArrayList<>();
		for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		}

		int sum[] = new int[N+1];

		sum[0]=0;
		for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		}

		int cnt = 0;
		if(sum[N]==M) cnt++;
		for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	} run {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Pair> lr = new ArrayList<>();
		for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		}

		int sum[] = new int[N+1];

		sum[0]=0;
		for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		}

		int cnt = 0;
		if(sum[N]==M) cnt++;
		for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	} 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 ArrayList<Pair> lr = new ArrayList<>(); lr new ArrayList<>() for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		} {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		} int L=sc.nextInt(); L sc.nextInt() sc.nextInt sc L-- L int R=sc.nextInt(); R sc.nextInt() sc.nextInt sc R-- R lr.add(new Pair(L, R)) lr.add lr new Pair(L, R) int sum[] = new int[N+1]; sum new int[N+1] N+1 N 1 sum[0]=0 sum[0] sum 0 0 for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		} {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		} Pair p = lr.get(i); p lr.get(i) lr.get lr i sum[p.L] += -1 sum[p.L] sum p.L p p.L -1 1 sum[p.R+1] += 1 sum[p.R+1] sum p.R+1 p.R p p.R 1 1 int cnt = 0; cnt 0 if(sum[N]==M) cnt++; sum[N]==M sum[N] sum N M cnt++ cnt for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		} int i=N-1; int i=N-1; i N-1 N 1 i>=0 i 0 i-- i-- i {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		} {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		} sum[i] += sum[i+1] sum[i] sum i sum[i+1] sum i+1 i 1 if(sum[i]==M) cnt++; sum[i]==M sum[i] sum i M cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt sc.close() sc.close sc class Pair{
		int L;
		int R;
		Pair(int L, int R){
			this.L=L;
			this.R=R;
		}
	} Pair int L; L int R; R Pair(int L, int R){
			this.L=L;
			this.R=R;
		} Pair {
			this.L=L;
			this.R=R;
		} this.L=L this.L this this.L L this.R=R this.R this this.R R int L L int R R public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair{
		int L;
		int R;
		Pair(int L, int R){
			this.L=L;
			this.R=R;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Pair> lr = new ArrayList<>();
		for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		}

		int sum[] = new int[N+1];

		sum[0]=0;
		for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		}

		int cnt = 0;
		if(sum[N]==M) cnt++;
		for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair{
		int L;
		int R;
		Pair(int L, int R){
			this.L=L;
			this.R=R;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Pair> lr = new ArrayList<>();
		for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		}

		int sum[] = new int[N+1];

		sum[0]=0;
		for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		}

		int cnt = 0;
		if(sum[N]==M) cnt++;
		for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair{
		int L;
		int R;
		Pair(int L, int R){
			this.L=L;
			this.R=R;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		ArrayList<Pair> lr = new ArrayList<>();
		for(int i=0; i<M; i++) {
			int L=sc.nextInt(); L--;
			int R=sc.nextInt(); R--;
			lr.add(new Pair(L, R));
		}

		int sum[] = new int[N+1];

		sum[0]=0;
		for(int i=0; i<M; i++) {
			Pair p = lr.get(i);
			sum[p.L] += -1;
			sum[p.R+1] += 1;
		}

		int cnt = 0;
		if(sum[N]==M) cnt++;
		for(int i=N-1; i>=0; i--) {
			sum[i] += sum[i+1];
			if(sum[i]==M) cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}
}
