#include <iostream>
using namespace std;

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }
        bool* player = new bool [n];
        for (int i = 0; i < n; i++) {
            player[i] = true;
        }
        int retireNum = 0, count = 0, i = 0;
        while (retireNum < n - 1) {
            if (player[i]) {
                count++;
                if (count == m) {
                    player[i] = false;
                    retireNum++;
                    count = 0;
                }
            }
            i++;
            if (i >= n) {
                i = i % n;
            }
        }
        for (int i = 0; i < n; i++) {
            if (player[i]) {
                cout << i + 1 << endl;
            }
        }
        delete[] player;
    }
}