#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int n,m;
vector<int> member;//<num>

void solve() {
  int temp;
  member.clear();
  for(int i=1;i<=n;i++) { //initializing member
    member.push_back(i);
  }

  int pass = 0;
  int kill = 0;
  vector<int>::iterator it = member.end()-1;

  while(kill < n-1) {
    if(it != member.end()-1) {
      it++;
    }
    else {
      it = member.begin();
    }
    pass++;
    if(pass == m) {
      pass = 0;
      member.erase(it);
      it--;
      kill++;
    }
  }
  cout << member[0] << endl;
}

int main() {
  while(cin >> n >> m) {
    if(n==0 && m==0) break;
    solve();
  }
}