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



int main(){
  int n,m;
  while(true){
    cin >> n >> m;
    if(n+m == 0)break;
    vector<int> vec;
    for(int i=1;i<=n;i++)
      vec.push_back(i);
     
vector<int>::iterator it = vec.begin(); 
    while(vec.size() > 1){
      
      for(int i=1;i < m;i++){
	if(it == vec.end())it = vec.begin();
	it++;
	if(it == vec.end())it = vec.begin();
      }
     
      it = vec.erase(it);
   
    }
    cout << vec[0] << endl;
  }
  return 0;
}