#include <iostream>
#include <vector>

using namespace std;

int main ()
{
    int n, m;

    while (cin >> n >> m, n || m) {
        bool wa[1000];
        int res = n;

        for (int i = 0; i < n; i++)
            wa[i] = true;

        int tm = n - 1;
        while (res > 1) {
            int cnt = 0;
            
            while (cnt < m) {
                tm = (tm + 1) % n;
                if (wa[tm])
                    cnt++;
            }
            wa[tm] = false;
            res--;
        }

        for (int i = 0; i < n; i++)
            if (wa[i])
                cout << i + 1 << endl;
    }

    return 0;
}