def solve(n, m, l, r)
  st = Array.new(m + 2){ |i| i }
  ans = [0, n - m].max
  n.times{ |i|
    r[i].succ.times{ |j| st[j] += 1 }
    ans = [ans, st.max - (l[i] + m + 1)].max
  }
  ans
end

n, m = gets.split.map(&:to_i)
l, r = n.times.map { gets.split.map(&:to_i) }.transpose
p solve(n, m, l, r)

