#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    bool used[1010] = {};
    int cnt = 0;
    vector<int> ans;
    for (int i = 0; ans.size() < n; ++i) {
      i %= n;
      if (used[i]) continue;
      cnt++;

      if (cnt == m) {
        used[i] = true;
        cnt = 0;
        ans.push_back(i + 1);
      }
    }

    cout << ans.back() << endl;
  }
}