import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

auto readNum(T)(){
  return readln.chomp.to!T;
}

auto readNums(T)(){
  return readln.chomp.split.to!(T[]);
}

void main(){
  auto nm = readNums!int;
  int maxGate = nm[0]+1, minGate = 0;

  foreach(i; 0 .. nm[1]){
    auto g = readNums!int;
    minGate = max(minGate, g[0]);
    maxGate = min(maxGate, g[1]);
  }

  int ret = maxGate - minGate + 1;
  writeln(ret >= 0 ? ret : 0);
}
