#include<iostream>
#include<list>
using namespace std;

int main()
{
	int n, m;
	list<int> members;
	list<int>::iterator it;
	int i;

	while (cin>>n>>m, n||m) {
		while ( !members.empty() )
			members.pop_back();
		for (i = 0; i < n; i++)
			members.push_back(i+1);
		i = 0;
		it = members.begin();
		while ( members.size() > 1 ) {
			if (++i >= m) {
				i = 0;
				members.erase(it++);
			} else {
				it++;
			}
			if (it == members.end()) {
				it = members.begin();
			}
		}
		cout<<*members.begin()<<endl;
	}

	return 0;
}