arr = gets.split(" ")
$h = arr[0].to_i
$w = arr[1].to_i
$cell = [0, 1]
$lst = 0;

def mh_distance(a, b) 
  return (a[0] - b[0]).abs + (a[1] - b[1]).abs 
end

($h).times do |i|
  arr = gets.split(" ")
  a = arr[0].to_i
  b = arr[1].to_i
  if ($cell[1] >= a && $cell[1] <= b) 
    new_cell = [i+1, b+1]
  else
    new_cell = [i+1, $cell[1]]
  end 
  if new_cell[1] > $w 
    puts(-1)
  else
    $lst += mh_distance($cell, new_cell)
    puts($lst)
  end
  $cell = new_cell
end
