#include<iostream>
#include<vector>
using namespace std;

int main(void){
  vector<int> v;
  int n,m;
  while(cin >> n >> m){
    if(n==0&&m==0)
      break;
    int sm = m - 1;
    //int memn = n;
    for(int i=1;i<=n;i++){
      v.push_back(i);
    }
    vector<int>::iterator del = v.begin();
    int index = sm;
    while(n>1){
      //cout << v[index] << endl;
      v.erase(del+index);
      n--;
      index += sm;
      //     cout << index << " " << v.size() << endl;
      if(index>=n)
	index %= n;
    }
    cout << v[0] << endl;
    v.clear();
  }
  return 0;
}