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

int main()
{
	int a, b;
	while (cin >> a >> b, a | b) {
		int c = a;
		bool flag[1000]{};
		int now = 0;
		for (; a != 1;a--) {
			int k = 0;
			for(;;now++) {
				if (!flag[now%c]) {
					k++; 
					if (k == b) {
						flag[now%c] = true;
						break;
					}
				}
			 }
		}
		for (int i = 0; i < c; i++) {
			if (!flag[i]) {
				cout << i + 1 << endl;
			}
		}
	}
}