#include <bits/stdc++.h>

using namespace std;

int main() {

    int n, m;

    while(cin >> n >> m, n | m) {

        vector<int> circle;

        for(int i = 1; i <= n; ++i) {
            circle.push_back(i);
        }

        for(int i = m; circle.size() != 1; i = (i + m - 1) % circle.size() + 1) {
            circle.erase(circle.begin() + i - 1);
            --i;
        }

        cout << circle[0] << endl;

    }

}