//37
#include<iostream>
#include<vector>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    vector<int> c(n);
    for(int i=0;i<n;i++){
      c[i]=i+1;
    }
    vector<int>::iterator it=c.begin();
    while(c.size()!=1){
      it=c.erase(c.begin()+(it-c.begin()+m-1)%c.size());
    }
    cout<<c[0]<<endl;
  }
  return 0;
}