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

int main(){
    int n, m;
    while( cin >> n >> m, n||m ){
        vector<int> ring(0);
        for(int i = 1; i <= n; i++){
            ring.push_back(i);
        }
        int j = 0;
        while( ring.size() > 1 ){
            j = (j + m - 1) % ring.size();
            ring.erase(ring.begin()+j);
        }
        cout << ring[0] << endl;
    }
    return 0;
}