import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int M = Integer.parseInt(tmp[1]);

		List<Integer> L = new ArrayList<Integer>();
		List<Integer> R = new ArrayList<Integer>();

		for(int i = 0;i<M;i++){
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		}

		L.sort(null);
		R.sort(null);
		int max = R.get(0);
		int min = L.get(L.size()-1);

		if(max-min+1<0){
			System.out.println(0);
		}else{
			System.out.println(max-min + 1);
		}



	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int M = Integer.parseInt(tmp[1]);

		List<Integer> L = new ArrayList<Integer>();
		List<Integer> R = new ArrayList<Integer>();

		for(int i = 0;i<M;i++){
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		}

		L.sort(null);
		R.sort(null);
		int max = R.get(0);
		int min = L.get(L.size()-1);

		if(max-min+1<0){
			System.out.println(0);
		}else{
			System.out.println(max-min + 1);
		}



	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int M = Integer.parseInt(tmp[1]);

		List<Integer> L = new ArrayList<Integer>();
		List<Integer> R = new ArrayList<Integer>();

		for(int i = 0;i<M;i++){
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		}

		L.sort(null);
		R.sort(null);
		int max = R.get(0);
		int min = L.get(L.size()-1);

		if(max-min+1<0){
			System.out.println(0);
		}else{
			System.out.println(max-min + 1);
		}



	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int M = Integer.parseInt(tmp[1]);

		List<Integer> L = new ArrayList<Integer>();
		List<Integer> R = new ArrayList<Integer>();

		for(int i = 0;i<M;i++){
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		}

		L.sort(null);
		R.sort(null);
		int max = R.get(0);
		int min = L.get(L.size()-1);

		if(max-min+1<0){
			System.out.println(0);
		}else{
			System.out.println(max-min + 1);
		}



	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] tmp = br.readLine().split(" "); tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int N = Integer.parseInt(tmp[0]); N Integer.parseInt(tmp[0]) Integer.parseInt Integer tmp[0] tmp 0 int M = Integer.parseInt(tmp[1]); M Integer.parseInt(tmp[1]) Integer.parseInt Integer tmp[1] tmp 1 List<Integer> L = new ArrayList<Integer>(); L new ArrayList<Integer>() List<Integer> R = new ArrayList<Integer>(); R new ArrayList<Integer>() for(int i = 0;i<M;i++){
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		} int i = 0; int i = 0; i 0 i<M i M i++ i++ i {
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		} {
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		} tmp = br.readLine().split(" ") tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " L.add(Integer.parseInt(tmp[0])) L.add L Integer.parseInt(tmp[0]) Integer.parseInt Integer tmp[0] tmp 0 R.add(Integer.parseInt(tmp[1])) R.add R Integer.parseInt(tmp[1]) Integer.parseInt Integer tmp[1] tmp 1 L.sort(null) L.sort L null R.sort(null) R.sort R null int max = R.get(0); max R.get(0) R.get R 0 int min = L.get(L.size()-1); min L.get(L.size()-1) L.get L L.size()-1 L.size() L.size L 1 if(max-min+1<0){
			System.out.println(0);
		}else{
			System.out.println(max-min + 1);
		} max-min+1<0 max-min+1 max-min max min 1 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(max-min + 1);
		} System.out.println(max-min + 1) System.out.println System.out System System.out max-min + 1 max-min max min 1 String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int M = Integer.parseInt(tmp[1]);

		List<Integer> L = new ArrayList<Integer>();
		List<Integer> R = new ArrayList<Integer>();

		for(int i = 0;i<M;i++){
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		}

		L.sort(null);
		R.sort(null);
		int max = R.get(0);
		int min = L.get(L.size()-1);

		if(max-min+1<0){
			System.out.println(0);
		}else{
			System.out.println(max-min + 1);
		}



	}
} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int M = Integer.parseInt(tmp[1]);

		List<Integer> L = new ArrayList<Integer>();
		List<Integer> R = new ArrayList<Integer>();

		for(int i = 0;i<M;i++){
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		}

		L.sort(null);
		R.sort(null);
		int max = R.get(0);
		int min = L.get(L.size()-1);

		if(max-min+1<0){
			System.out.println(0);
		}else{
			System.out.println(max-min + 1);
		}



	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int M = Integer.parseInt(tmp[1]);

		List<Integer> L = new ArrayList<Integer>();
		List<Integer> R = new ArrayList<Integer>();

		for(int i = 0;i<M;i++){
			tmp = br.readLine().split(" ");
			L.add(Integer.parseInt(tmp[0]));
			R.add(Integer.parseInt(tmp[1]));
		}

		L.sort(null);
		R.sort(null);
		int max = R.get(0);
		int min = L.get(L.size()-1);

		if(max-min+1<0){
			System.out.println(0);
		}else{
			System.out.println(max-min + 1);
		}



	}
}
