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

const int MAXN = 1000;
int n, m;
bool flag[MAXN];

int main() {
  while(cin >> n >> m && (n|m)) {
    fill(flag, flag+MAXN, true);
    for(int i = 0, j = 0; i < n-1; ++i) {
      for(int k = 0; ; j = (j+1)%n) {
        if(flag[j]) {
          if(++k == m) break;
        }
      }
      flag[j] = false;
    }
    for(int i = 0; i < n; ++i) {
      if(flag[i]) {
        cout << i+1 << endl;
        break;
      }
    }
  }
  return 0;
}