until (a = $<.gets.split.map(&:to_i)) == [0, 0]
  n, m = a
  circle = [*1..n]
  try = ->(po) {
    return circle.first if circle.size == 1
    po += m - 1
    po = po - circle.size while po >= circle.size
    circle = circle[0...po] + circle[po + 1..-1]
    try.(po)
  }
  puts try.(n)
end
