#include<iostream>
using namespace std;
bool b[1001];
int main() {
	int n, m;
	while (cin >> n >> m&&n != 0 && m != 0) {
		for (int i = 0; i <= n; i++) {
			b[i] = true;
		}
		int a = 1, d = n;
		while (d > 1) {
			int c = 1;
			while (c < m) {
				if (b[a]) {
					c++;
				}
				a++;
				if (a >= n + 1)
					a = 1;
			}
			while (b[a] == false) {
				a++;
				if (a >= n + 1) a = 1;
			}
			b[a] = false;
			d--;
		}
		for (int i = 1; i <= n; i++) {
			if (b[i]) {
				cout << i << endl;
				break;
			}
		}
	}
}