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