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

int main() {
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;
        queue<int> members;
        for (int i = 1; i <= n; i++) {
            members.push(i);
        }
        while (members.size() != 1) {
            int cnt = 0;
            while (true) {
                int member = members.front(); members.pop();
                cnt++;
                if (cnt == m) break;
                members.push(member);
            }
        }
        cout << members.front() << endl;
    }
    return 0;
}