#include <cstdio>
#include <list>
using namespace std;

int n;
int m;

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0) return 0;

    list<int> l;
    for (int i=1; i<=n; i++) {
      l.push_back(i);
    }

    list<int>::iterator itr = l.begin();
    while (l.size() > 1) {
      for (int i=0; i<m-1; i++) {
        ++itr;
        if (itr == l.end()) itr = l.begin();
      }

      itr = l.erase(itr);
      if (itr == l.end()) itr = l.begin();
    }

    printf("%d\n", l.front());
  }
}