#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    while (cin >> n, n)
    {
        cin >> m;
        vector<int> ans;
        for (int i = 0; i <= n; i++)
            ans.push_back(i);
        int cnt = 0;
        int i = 1;

        while (cnt != n - 1)
        {
            if (i > ans.size() - 1)
                i = 1;
            int sum = 1;
            while (sum != m)
            {
                sum++;
                i++;
                if (i > ans.size() - 1)
                    i = 1;
            }
            ans.erase(ans.begin() + i);
            cnt++;
        }
        OP(ans[1]);
    }
    return 0;
}
