head = gets
h = head.split(/ /)
n = h[0].to_i
m = h[1].to_i

gate = []
while line = gets
  break if line == "\n"
  l = line.split(/ /)
  gate.push([l[0].to_i, l[1].to_i])
end

min = 1
max = n
gate.each do |g|
  if min < g[0]
    min = g[0]
  end
  if max > g[1]
    max = g[1]
  end
end
ans = max - min + 1
p ans