#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int solve(int n, int m){
	vector< int > vec;
	vector< int >::iterator it;
	vector< int >::iterator eit;
	int i = 0;
	for (i = 1; i <= n; i++){
		vec.push_back(i);
	}
	i = 0;
	it = vec.end();
	eit = vec.end();
	while (vec.size() > 1){
		for (int j = 0; j<m-1; j++){
			if (it == eit){
				// cout << "it == eit" << endl;
				it = vec.begin();
			}
			// cout << "now" << endl;
			++it;
			// cout << "now2" << endl;

		}
		if (it != vec.end()){
			// cout << *it << endl;
			it = vec.erase(it);
		} else {
			it = vec.begin();
			// cout << "begin *it = " << *it << endl;
			it = vec.erase(it);
		}
		eit = vec.end();

		/*vector< int >::iterator itt = vec.begin();
		for (; itt != vec.end(); itt++){
			cout << *itt << " ";
		}*/
	}
	return vec.front();
}

int main(){
	int n, m;
	while (cin >> n >> m, n || m){
		cout << solve(n, m) << endl;
	}
	
	return 0;
}