loop do
  n, m = gets.split.map(&:to_i)
  if n == 0 && m == 0 then
  	break
  end
  table = (1..n).to_a
  del = m - 1
  while table.size > 1 do
  	table.delete_at(del)
  	del += m - 1
  	while del >= table.size do
  	  del -= table.size
    end
  end
  puts table
end