#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

bool u[1010];
int n, m;
bool check() {
  int tmp = 0;
  REP(i, n) if(u[i]) tmp++;
  if(tmp == n) return false;
  else return true;
}

signed main(void)
{
  while(true) {
    cin >> n >> m;
    if(!n && !m) break;
    int a = n-1;
    memset(u, false, sizeof(u));
    while(check()) {
      REP(i, m) {
        a++;
        if(a >= n) a = 0;
        while(u[a]) {
          a++;
          if(a >= n) a = 0;
        }
      }
      u[a] = true;
      //cout << a << " ";
    }
    //cout << endl;
    cout << a+1 << endl;
  }

  return 0;
}