#include<iostream>
#include<vector>
using namespace std;
int main(){
  while(1){ 
 int n,m;
  vector<int> p;
  cin>>n>>m;
  if(n==0)break;
  int k;
  for(int i=1;i<=n;i++)p.push_back(i);
  k=n-1;
  while(p.size()!=1){
    k=(k+m)%p.size();
    p.erase(p.begin()+k);
    k--;
  }
  cout<<p[0]<<endl;
}
  return 0;
}