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

int main()
{
    int n,m;
    while(cin >> n >> m && n || m)
    {
        vector<int> data(n);
        int i=1;

        for(int i=0; i<n; i++){
            data[i] = i+1;
        }
        for(vector<int>::iterator it = data.begin(); data.size() != 1;){
            if(it == data.end()){
                it = data.begin();
            }
            if(i%m == 0){
                it = data.erase(it);
            }else{
                it++;
            }
            i++;
        }
        cout << data[0] << endl;
    }

    return 0;
}