#include<queue>
#include<iostream>
using namespace std;
main(){
  int n,m;
  queue<int> poteto;
  while(1){
    cin>>n>>m;
    if(n==0&&m==0) break;
    for(int i=1;i<=n;i++){
      poteto.push(i);
    }
    while(poteto.size()>1){
      for(int j=0;j<m-1;j++){
	poteto.push(poteto.front());
	poteto.pop();
      }
      poteto.pop();
    }
    cout<<endl;
    cout<<poteto.front()<<endl;
    poteto.pop();
  }
}