#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void erase(vector<int> &v, int m) { // erase mth
    m = m % v.size();
    v.erase(v.begin() + m);
    vector<int> w;
    FOR(i,m,v.size()) {
        w.push_back(v[i]);
    }
    REP(i,m) {
        w.push_back(v[i]);
    }
    swap(v,w);
}

int Joseph(vector<int> v, int m) {
    while(v.size()-1) {
        erase(v,m-1);
    }
    return v[0];
}

int main() {
    int n, m;
    while(cin >> n >> m, n + m) {
        vector<int> v;
        REP(i,n) {
            v.push_back(i+1);
        }
        cout << Joseph(v,m) << endl;
    }
    return 0;
}