#include <iostream>

using namespace std;

int main()
{
	int n, m;
	bool* participant;
	
	while (true) {
		cin >> n >> m;
		if (n==0 && m==0) break;
		
		participant = new bool[n];
		for (int i=0; i<n; i++) participant[i] = true;
		
		int index = 0;
		for (int cnt = n; cnt > 0; cnt--) {
			for (int step = m-1; ; index = (index + 1) % n) {
				if (participant[index]) {
					if (step==0) break;
					else step--;
				}
			}
			participant[index] = false;
			// cout << index+1 << " ";
		}
		
		cout << index+1 << endl;
		
		delete[] participant;
	}
	
	return 0;
}