import java.util.*;
import java.math.*;
class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int m = stdIn.nextInt();
    long[] l = new long[m];
    long[] r = new long[m];
    for(int i = 0;i<r.length;i++) {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    }
    long maxGate = 1000000000;
    long minGate = 0;
    for(int i = 0;i<l.length;i++) {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    }
    long count = maxGate - minGate + 1;
    if(count<=0) System.out.println(0);
    else System.out.println(count);
  }
} import java.util.*; util.* java import java.math.*; math.* java class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int m = stdIn.nextInt();
    long[] l = new long[m];
    long[] r = new long[m];
    for(int i = 0;i<r.length;i++) {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    }
    long maxGate = 1000000000;
    long minGate = 0;
    for(int i = 0;i<l.length;i++) {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    }
    long count = maxGate - minGate + 1;
    if(count<=0) System.out.println(0);
    else System.out.println(count);
  }
} Main public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int m = stdIn.nextInt();
    long[] l = new long[m];
    long[] r = new long[m];
    for(int i = 0;i<r.length;i++) {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    }
    long maxGate = 1000000000;
    long minGate = 0;
    for(int i = 0;i<l.length;i++) {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    }
    long count = maxGate - minGate + 1;
    if(count<=0) System.out.println(0);
    else System.out.println(count);
  } main {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int m = stdIn.nextInt();
    long[] l = new long[m];
    long[] r = new long[m];
    for(int i = 0;i<r.length;i++) {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    }
    long maxGate = 1000000000;
    long minGate = 0;
    for(int i = 0;i<l.length;i++) {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    }
    long count = maxGate - minGate + 1;
    if(count<=0) System.out.println(0);
    else System.out.println(count);
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int m = stdIn.nextInt(); m stdIn.nextInt() stdIn.nextInt stdIn long[] l = new long[m]; l new long[m] m long[] r = new long[m]; r new long[m] m for(int i = 0;i<r.length;i++) {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    } int i = 0; int i = 0; i 0 i<r.length i r.length r r.length i++ i++ i {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    } {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    } l[i] = stdIn.nextInt() l[i] l i stdIn.nextInt() stdIn.nextInt stdIn r[i] = stdIn.nextInt() r[i] r i stdIn.nextInt() stdIn.nextInt stdIn long maxGate = 1000000000; maxGate 1000000000 long minGate = 0; minGate 0 for(int i = 0;i<l.length;i++) {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    } int i = 0; int i = 0; i 0 i<l.length i l.length l l.length i++ i++ i {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    } {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    } minGate = Math.max(minGate,l[i]) minGate Math.max(minGate,l[i]) Math.max Math minGate l[i] l i maxGate = Math.min(maxGate,r[i]) maxGate Math.min(maxGate,r[i]) Math.min Math maxGate r[i] r i long count = maxGate - minGate + 1; count maxGate - minGate + 1 maxGate - minGate maxGate minGate 1 if(count<=0) System.out.println(0);
    else System.out.println(count); count<=0 count 0 System.out.println(0) System.out.println System.out System System.out 0 System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.*;
import java.math.*;
class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int m = stdIn.nextInt();
    long[] l = new long[m];
    long[] r = new long[m];
    for(int i = 0;i<r.length;i++) {
      l[i] = stdIn.nextInt();
      r[i] = stdIn.nextInt();
    }
    long maxGate = 1000000000;
    long minGate = 0;
    for(int i = 0;i<l.length;i++) {
      minGate = Math.max(minGate,l[i]);
      maxGate = Math.min(maxGate,r[i]);
    }
    long count = maxGate - minGate + 1;
    if(count<=0) System.out.println(0);
    else System.out.println(count);
  }
}
