n, m = gets.rstrip.split.map(&:to_i)
lrs = m.times.map{ gets.rstrip.split.map(&:to_i) }

ans = ('1' * n).to_i
lr = lrs.shift
l1 = lr[0]
r1 = lr[1]
lrs.each do | lr |
  l2, r2 = lr[0], lr[1]

  # 1 l1---r1
  # 2       l2----r2
  # or 
  # 1       l1----r1
  # 2 l2---r2
  if r1 < l2 or l1 > r2
    #p 0
    exit
  end

  # 1 l1-----r1
  # 2 l2-----r2
  if l1 == l2 and r1 == r2
    next
  end

  # 1 l1------r1
  # 2     l2-----r2
  if l1 <= l2 and r1 >= l2 and r1 <= r2 and  r1 >= l2
    l1 = l2
    next
  end

  # 1   l1------r1
  # 2 l2-----r2
  if l1 >= l2 and l1 <= r2 and r1 >= r2 and  r2 >= l1
    r1 = r2
    next
  end

  # 1 l1--------r1
  # 2   l2---r2
  if l1 < l2 and r1 > r2
    l1 = l2
    r1 = r2
    next
  end

  # 1   l1---r1
  # 2 l2--------r2
  if l2 < l1 and r2 > r1
    next
  end
end

p (r1 - l1) + 1
