import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int lower = 0;
    int upper = n+1;

    for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    }
    if (lower > upper){
      System.out.println(0);
      return;
    }
    System.out.println(upper-lower+1);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int lower = 0;
    int upper = n+1;

    for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    }
    if (lower > upper){
      System.out.println(0);
      return;
    }
    System.out.println(upper-lower+1);
  }
} Main public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int lower = 0;
    int upper = n+1;

    for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    }
    if (lower > upper){
      System.out.println(0);
      return;
    }
    System.out.println(upper-lower+1);
  } main {
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int lower = 0;
    int upper = n+1;

    for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    }
    if (lower > upper){
      System.out.println(0);
      return;
    }
    System.out.println(upper-lower+1);
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan int lower = 0; lower 0 int upper = n+1; upper n+1 n 1 for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    } int j=0; int j=0; j 0 j<m j m j++ j++ j {
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    } {
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    } int low = scan.nextInt(); low scan.nextInt() scan.nextInt scan int high = scan.nextInt(); high scan.nextInt() scan.nextInt scan if (lower < low){
        lower = low;
      } lower < low lower low {
        lower = low;
      } lower = low lower low if (high < upper){
        upper = high;
      } high < upper high upper {
        upper = high;
      } upper = high upper high if (lower > upper){
      System.out.println(0);
      return;
    } lower > upper lower upper {
      System.out.println(0);
      return;
    } System.out.println(0) System.out.println System.out System System.out 0 return; System.out.println(upper-lower+1) System.out.println System.out System System.out upper-lower+1 upper-lower upper lower 1 String[] args args public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int lower = 0;
    int upper = n+1;

    for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    }
    if (lower > upper){
      System.out.println(0);
      return;
    }
    System.out.println(upper-lower+1);
  }
} public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int lower = 0;
    int upper = n+1;

    for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    }
    if (lower > upper){
      System.out.println(0);
      return;
    }
    System.out.println(upper-lower+1);
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    int lower = 0;
    int upper = n+1;

    for (int j=0;j<m;j++){
      int low = scan.nextInt();
      int high = scan.nextInt();
      if (lower < low){
        lower = low;
      }
      if (high < upper){
        upper = high;
      }
    }
    if (lower > upper){
      System.out.println(0);
      return;
    }
    System.out.println(upper-lower+1);
  }
}
