import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int a[] = new int[n];
    int l = 0;
    int r = 0;
    int min = 0;
    int max = n;
    int ans = 0;

    for (int i=0; i<m; i++){
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      if (l>min) { min=l; }
      if (max>r) { max=r; }
    }
    
    ans = max-min+1;
    if (ans<0) { ans=0; }
    System.out.println(ans);
    
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int a[] = new int[n];
    int l = 0;
    int r = 0;
    int min = 0;
    int max = n;
    int ans = 0;

    for (int i=0; i<m; i++){
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      if (l>min) { min=l; }
      if (max>r) { max=r; }
    }
    
    ans = max-min+1;
    if (ans<0) { ans=0; }
    System.out.println(ans);
    
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int a[] = new int[n];
    int l = 0;
    int r = 0;
    int min = 0;
    int max = n;
    int ans = 0;

    for (int i=0; i<m; i++){
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      if (l>min) { min=l; }
      if (max>r) { max=r; }
    }
    
    ans = max-min+1;
    if (ans<0) { ans=0; }
    System.out.println(ans);
    
  } main {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int a[] = new int[n];
    int l = 0;
    int r = 0;
    int min = 0;
    int max = n;
    int ans = 0;

    for (int i=0; i<m; i++){
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      if (l>min) { min=l; }
      if (max>r) { max=r; }
    }
    
    ans = max-min+1;
    if (ans<0) { ans=0; }
    System.out.println(ans);
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int a[] = new int[n]; a new int[n] n int l = 0; l 0 int r = 0; r 0 int min = 0; min 0 int max = n; max n int ans = 0; ans 0 for (int i=0; i<m; i++){
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      if (l>min) { min=l; }
      if (max>r) { max=r; }
    } int i=0; int i=0; i 0 i<m i m i++ i++ i {
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      if (l>min) { min=l; }
      if (max>r) { max=r; }
    } {
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      if (l>min) { min=l; }
      if (max>r) { max=r; }
    } l = Integer.parseInt(sc.next()) l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r = Integer.parseInt(sc.next()) r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (l>min) { min=l; } l>min l min { min=l; } min=l min l if (max>r) { max=r; } max>r max r { max=r; } max=r max r ans = max-min+1 ans max-min+1 max-min max min 1 if (ans<0) { ans=0; } ans<0 ans 0 { ans=0; } ans=0 ans 0 System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int a[] = new int[n];
    int l = 0;
    int r = 0;
    int min = 0;
    int max = n;
    int ans = 0;

    for (int i=0; i<m; i++){
      l = Integer.parseInt(sc.next());
      r = Integer.parseInt(sc.next());
      if (l>min) { min=l; }
      if (max>r) { max=r; }
    }
    
    ans = max-min+1;
    if (ans<0) { ans=0; }
    System.out.println(ans);
    
  }
}
