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

int main () {
	int n, m;
	while (cin >> n >> m, n || m) {
		vector<int> member;
		for (int i = 1; i <= n; i++) {
			member.push_back(i);
		}
		m--;
		for (int i = m; member.size() != 1; i = (i + m) % member.size()) {
			member.erase(member.begin() + i);
		}
		cout << member[0] << endl;
	}
	return 0;
}