#include<iostream>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int succ[2000], pred[2000];

void kill(int n){
    succ[pred[n]] = succ[n];
    pred[succ[n]] = pred[n];
}

int main(){
    int n,m;
    while(cin>>n>>m, n){
        rep(i,n){
            succ[i] = (i+1)%n;
            pred[i] = (i-1+n)%n;
        }
        int cur = 0;
        rep(i,n){
            rep(i,m) cur = succ[cur];
            kill(cur);
            // cout << " " << cur << endl;
        }
        if(cur==0) cur=n;
        cout << cur << endl;
    }
}