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

int n, m;
vector<int> vec;

void setVec();
void loop();

int main(){
    while(cin >>n >>m){
        if(n == 0 && m == 0) break;
        vec.clear();
        setVec();
        loop();
        cout <<vec[0] <<endl;
    }
}

void setVec(){
    for(int i = 1; i <= n; i++){
        vec.push_back(i);
    }
}

void loop(){
    int cnt = 1;
    vector<int>::iterator it = vec.begin();
    while(vec.size() != 1){
        if(it == vec.end()){
            it = vec.begin();
        }
        if(cnt == m){
            vec.erase(it);
            cnt = 1;
            continue;
        }
        cnt++;
        it++;
    }
}