def f(n, m)
  if n == 1
    return 1
  else
    return (f(n - 1, m) + m - 1) % n + 1
  end
end

def main(input = STDIN)
  while (n, m = input.gets.split(" ").map(&:to_i)) != [0, 0]
    puts f(n, m)
  end
end
main