#include <iostream>
#include <queue>

using namespace std;

int simulation(int n_player, int interval)
{
  int player;
  int counter = 0;
  queue<int> que;

  for(int i = 1; i <= n_player; ++i)
    que.push(i);

  while(que.size() > 1){
    player = que.front();
    que.pop();

    if(++counter == interval){
      counter = 0;
    } else {
      que.push(player);
    }
  }

  return que.front();
}

int main()
{
  int n_player, interval;

  while(cin>>n_player>>interval){
    if(n_player == 0 && interval == 0) break;

    cout << simulation(n_player, interval) << endl;
  }

  return 0;
}