#include <bits/stdc++.h>
using namespace std;

int main() {
	for(int n, m; cin >> n >> m && (n | m);) {
		vector<int> players(n);
		iota(players.begin(), players.end(), 1);

		int idx = m - 1;
		while(players.size() > 1) {
			players.erase(players.begin() + idx);
			idx = (idx + m - 1) % players.size();
		}

		cout << players.front() << endl;
	}

	return EXIT_SUCCESS;
}