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

int main() {
    int n, m;
    while (cin >> n >> m, (n || m)) {
        int rest = n;
        int pos = n-1;
        vector<int> v(n, 0);
        while (1 < rest) {
            int cnt = 0;
            while (1) {
                pos = (pos + 1) % n;
                if (v[pos] == 0) cnt ++;
                if (cnt == m) break;
            }
            v[pos] = 1;
            rest --;
        }
        int ans = 0;
        for (int i=0; i<(int)v.size(); ++i) {
            if (v[i] == 0) {
                ans = i+1;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}