loop{
  n,m = gets.split.map(&:to_i)
  break if (n|m)==0
  c = (1..n).to_a
  pos = c.length-1
  tmp = 0 if false
  loop{
    pos=(pos+m)%c.length
    tmp = c.delete_at(pos)
    pos-=1
    break if c.empty?
  }
  puts tmp
}