#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

void init(const list<int>::iterator&begin, const list<int>::iterator&end) {
	auto itr = begin;
	for (int i = 0; itr != end; ++i) {
		*itr = i;
		++itr;
	}
}
signed main()
{
	int n, m;
	while (cin >> n >> m, n) {
		list<int>p(n); init(ALL(p));
		auto potate = prev(p.end());
		while (p.size() > 1) {
			REP(i, m) {
				advance(potate, 1);
				if (potate == p.end())potate = p.begin();
			}
			auto foo = p.erase(potate);
			potate = prev(foo == p.begin() ? p.end() : foo);
		}
		cout << *potate + 1 << endl;
	}
}
