#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
//#include<algorithm>
//#include<cmath>
//#include<string>
using namespace std;
int main() {
	int n, m, ans;
	while (cin >> n >> m, n, m) {
		ans = m - 1;
		while (ans < (m - 1)*n) ans = (m*ans) / (m - 1) + 1;
		ans = n*m - ans;
		cout << ans << endl;
	}
	return 0;
}