#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int i, n, m;
  vector<int> data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    for(i=0; i<n; ++i)
      data.push_back(i+1);

    i = 0;
    while(data.size() != 1){
      i = i + m - 1;
      i %= data.size();
      data.erase(data.begin()+i);
    }

    cout << data[0] << endl;
    data.clear();
  }

  return 0;
}