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

int main() {
	int n, m;
	while (cin >> n >> m, n, m) {
		vector<int>v;
		for (int i = 1;i <= n;i++)v.push_back(i);

		int now = 0;
		for (int i = 0;i < n - 1;i++) {
			for (int j = 0;j < m - 1;j++) {
				now++;
				now %= n-i;
			}
			v.erase(v.begin() + now);
		}
		cout << v[0] << endl;
	}
	return 0;
}

