#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, m) {
    vector<int> seq(n);
    for (int i = 0; i < n; ++i)
      seq[i] = i + 1;

    while (seq.size() > 1) {
      rotate(seq.begin(), seq.begin() + (m - 1) % seq.size(), seq.end());
      seq.erase(seq.begin());
    }
    cout << seq[0] << endl;
  }
}
