#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector<bool> flag(n);
		for(int i = 0; i < n; ++i)
		{
			flag[i] = true;
		}
		int count = 0;
		int pos = 0;
		while(count < n)
		{
			int step = m;
			while(step > 0)
			{
				if(flag[pos])
				{
					--step;
				}
				++pos;
				pos %= n;
			}
			flag[(pos - 1 + n) % n] = false;
			++count;
		}
		cout << (pos - 1 + n) % n + 1 << endl;
	}
}

int main()
{
	solve();
	return(0);
}