def solve(n, m)
  array = Array.new(n)
  n.times do |i|
    array[i] = i + 1
  end
  
  pos = m - 1
  while array.size > 1 do
    array.delete_at(pos)
    pos += m - 1
    pos = pos % array.size
  end
  array[0]
end

loop do
  n, m = $stdin.gets.chomp.split(" ").map(&:to_i)
  break if n == 0 && m == 0
  p solve(n, m)
end