#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> a(n);
    iota(a.begin(), a.end(), 1);
    int pos = 0;
    while ((int)a.size() > 1) {
      pos = (pos + m - 1) % a.size();
      a.erase(a.begin() + pos);
    }
    cout << a[0] << endl;
  }

  return 0;
}
