#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

    int n, m;
    for (;;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        vector<int> players;
        players.reserve(n);
        for (int i = 1; i <= n; i++) players.push_back(i);
        int idx = m -1;
        while (players.size() > 1) {
            players.erase(players.begin()+idx);
            idx = (idx + m-1) % players.size();
        }
        printf("%d\n", players[0]);
    }
    return 0;
}
