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

int main(){

 
  int n;
  int m;
  while(cin >> n >> m){
    vector<int> v;
    vector<int>::iterator it;
    if(n==0&&m==0)
      break;
    for (int i = 1 ; i <= n; i++)
      v.push_back(i);
    it = v.begin();
    int index = m-1;
    while(n!=1){
      v.erase(it+index);
      n--;
      index += m-1;
      if(index>=n)
	index %= n;
    }
    cout << v[0] << endl;
  }

  return 0;
}