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

int main()
{	
	int n, m;

	cin >> n >> m;

	while (n > 0 || m > 0) {
		queue<int> a;

		for (int i = 1; i <= n; i++)
			a.push(i);

		for (int j = 0; j < n - 1; j++) {
			for (int i = 0; i < m - 1; i++) {
				int p = a.front();
				a.pop();
				a.push(p);
			}

			a.pop();
		}

		cout << a.front() << endl;

		cin >> n >> m;
	}

	return 0;
}

