import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      
      	int card = sc.nextInt();
      	int nam = sc.nextInt();
      	int max = -1;int min = 999999;
      
      for(int i = 0; i < nam ;i++){
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      }
      	int cnt = 0;
      	for(int i = max;i <=min;i++){
        cnt++;
        }

		System.out.print(cnt);
      	


    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      
      	int card = sc.nextInt();
      	int nam = sc.nextInt();
      	int max = -1;int min = 999999;
      
      for(int i = 0; i < nam ;i++){
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      }
      	int cnt = 0;
      	for(int i = max;i <=min;i++){
        cnt++;
        }

		System.out.print(cnt);
      	


    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      
      	int card = sc.nextInt();
      	int nam = sc.nextInt();
      	int max = -1;int min = 999999;
      
      for(int i = 0; i < nam ;i++){
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      }
      	int cnt = 0;
      	for(int i = max;i <=min;i++){
        cnt++;
        }

		System.out.print(cnt);
      	


    } main {
        Scanner sc = new Scanner(System.in);
      
      	int card = sc.nextInt();
      	int nam = sc.nextInt();
      	int max = -1;int min = 999999;
      
      for(int i = 0; i < nam ;i++){
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      }
      	int cnt = 0;
      	for(int i = max;i <=min;i++){
        cnt++;
        }

		System.out.print(cnt);
      	


    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int card = sc.nextInt(); card sc.nextInt() sc.nextInt sc int nam = sc.nextInt(); nam sc.nextInt() sc.nextInt sc int max = -1; max -1 1 int min = 999999; min 999999 for(int i = 0; i < nam ;i++){
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      } int i = 0; int i = 0; i 0 i < nam i nam i++ i++ i {
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      } {
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      } max = Math.max(max,sc.nextInt()) max Math.max(max,sc.nextInt()) Math.max Math max sc.nextInt() sc.nextInt sc min = Math.min(min,sc.nextInt()) min Math.min(min,sc.nextInt()) Math.min Math min sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 for(int i = max;i <=min;i++){
        cnt++;
        } int i = max; int i = max; i max i <=min i min i++ i++ i {
        cnt++;
        } {
        cnt++;
        } cnt++ cnt System.out.print(cnt) System.out.print System.out System System.out cnt String[] args args
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      
      	int card = sc.nextInt();
      	int nam = sc.nextInt();
      	int max = -1;int min = 999999;
      
      for(int i = 0; i < nam ;i++){
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      }
      	int cnt = 0;
      	for(int i = max;i <=min;i++){
        cnt++;
        }

		System.out.print(cnt);
      	


    }
}