import 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 = new int[m];
      int[] r = new int[m];
      int max = 0;
      int min = 1000000;
      int count = 0;
      for(int i = 0;i < m;i++){
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      }
      for(int i = 1;i <= n;i++){
      	if(max <= i && i <= min){
          count++;
        }
      }
      System.out.println(count);
    }
} import java.util.*; util.* java 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 = new int[m];
      int[] r = new int[m];
      int max = 0;
      int min = 1000000;
      int count = 0;
      for(int i = 0;i < m;i++){
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      }
      for(int i = 1;i <= n;i++){
      	if(max <= i && i <= min){
          count++;
        }
      }
      System.out.println(count);
    }
} Main public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int[] l = new int[m];
      int[] r = new int[m];
      int max = 0;
      int min = 1000000;
      int count = 0;
      for(int i = 0;i < m;i++){
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      }
      for(int i = 1;i <= n;i++){
      	if(max <= i && i <= min){
          count++;
        }
      }
      System.out.println(count);
    } main {
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int[] l = new int[m];
      int[] r = new int[m];
      int max = 0;
      int min = 1000000;
      int count = 0;
      for(int i = 0;i < m;i++){
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      }
      for(int i = 1;i <= n;i++){
      	if(max <= i && i <= min){
          count++;
        }
      }
      System.out.println(count);
    } 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 = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m int max = 0; max 0 int min = 1000000; min 1000000 int count = 0; count 0 for(int i = 0;i < m;i++){
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      } {
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      } l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc max = Math.max(max,l[i]) max Math.max(max,l[i]) Math.max Math max l[i] l i r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc min = Math.min(min,r[i]) min Math.min(min,r[i]) Math.min Math min r[i] r i for(int i = 1;i <= n;i++){
      	if(max <= i && i <= min){
          count++;
        }
      } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
      	if(max <= i && i <= min){
          count++;
        }
      } {
      	if(max <= i && i <= min){
          count++;
        }
      } if(max <= i && i <= min){
          count++;
        } max <= i && i <= min max <= i max i i <= min i min {
          count++;
        } count++ count System.out.println(count) System.out.println System.out System System.out count 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 = new int[m];
      int[] r = new int[m];
      int max = 0;
      int min = 1000000;
      int count = 0;
      for(int i = 0;i < m;i++){
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      }
      for(int i = 1;i <= n;i++){
      	if(max <= i && i <= min){
          count++;
        }
      }
      System.out.println(count);
    }
} 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 = new int[m];
      int[] r = new int[m];
      int max = 0;
      int min = 1000000;
      int count = 0;
      for(int i = 0;i < m;i++){
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      }
      for(int i = 1;i <= n;i++){
      	if(max <= i && i <= min){
          count++;
        }
      }
      System.out.println(count);
    }
} Main
import 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 = new int[m];
      int[] r = new int[m];
      int max = 0;
      int min = 1000000;
      int count = 0;
      for(int i = 0;i < m;i++){
      	l[i] = sc.nextInt();
        max = Math.max(max,l[i]);
        r[i] = sc.nextInt();
        min = Math.min(min,r[i]);
      }
      for(int i = 1;i <= n;i++){
      	if(max <= i && i <= min){
          count++;
        }
      }
      System.out.println(count);
    }
}
