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

int main() {
  int n, m, a;
  vector<int> v;
  while (1) {
    cin >> n >> m;
    if (!n && !m) break;
    v.clear();
    a = 0;
    for (int i=0; i<n; i++) v.push_back(i);
    while (v.size() > 1) {
      a = (a + m - 1) % v.size();
      v.erase(v.begin()+a);
    }
    cout << v[0]+1 << endl;
  }
  return 0;
}