#include <iostream>

using namespace std;
/** Problem0085 : Joseph's Potato **/
int main()
{
	int n, m, ans, idx;
	bool live[1000];
	
	while (cin >> n >> m && (n!=0 && m!=0)) {
		for (int i=0; i<1000; i++) live[i]=true;
		
		ans = 0; idx=0;
		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				while (live[(++idx)%n]!= true);
			}
			live[idx%n] = false;
		}
		cout << ((idx%n)==0 ? n : idx%n) << endl;
	}
	return 0;
}