#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m) {
		if (!n && !m)return 0;
		vector<int>v;
		for (int i = 0; i < n; i++)v.push_back(i + 1);
		int k = -1;
		while (v.size() != 1) {
			for (int i = 0; i < m; i++){
				k++;
				if (k == v.size())k = 0;
			}
			v.erase(v.begin() + k);
			k--;
		}
		cout << v[0] << endl;
	}
}