#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

ll arr[1000010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(6);

    int n, m;
    while (cin >> n >> m)
    {
        if (n == 0 && m == 0)
            break;

        int arr[1010] = {0};

        vector<int> v;
        int cnt = 0;
        int idx = 0;
        while ((int)v.size() != n)
        {
            if (arr[idx] == 0)
            {
                cnt++;
            }
            if (cnt == m)
            {
                arr[idx] = 1;
                v.push_back(idx);
                cnt = 0;
            }
            idx++;
            idx %= n;
        }
        cout << v[v.size() - 1] + 1 << endl;
    }
    return 0;
}
