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

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