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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n,m;
  while(cin>>n>>m,n+m) {
    vector<int> v;
    REP(i,n)
      v.push_back(i+1);
    int pos = -1;
    int size = n;
    while(v.size()>1) {
      pos = (pos+m)%v.size();
      v.erase(v.begin()+pos);
      pos--;
    }
    cout << v[0] << endl; 
  }
}