#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a){
    queue<int>q;
    int s=0;
    for(int i=1;i<=a;i++)q.push(i);
    while(1){
      s++;
      int p=q.front();q.pop();
      if(q.empty()){cout<<p<<endl;break;}
      if(s==b)s=0;
      else q.push(p);
    }
  }
}