#include <cstdio>
#include <vector>
using namespace std;

int n, m;

void solve(){
  vector<int> v;
  for(int i=1; i<=n; ++i){
    v.push_back(i);
  }
  while(v.size()!=1){
    for(int j=1; j<=m; ++j){
      int k=v[0];
      v.erase(v.begin());
      if(j!=m)
	v.push_back(k);
    }
  }
  printf("%d\n", v[0]);
}

int main(){
  while(scanf("%d %d", &n, &m), n){
    solve();
  }
}