#include<iostream>
#include<cstring>
using namespace std;
int n, m, cnt, turn, remain; bool x[1000000];
int main() {
	while (true) {
		cin >> n >> m;
		if (n == 0 && m == 0) { break; }
		turn = 1; cnt = 1;
		remain = n;
		memset(x, false, sizeof(x));
		while (remain > 1) {
			cnt = 0;
			while (true) {
				if (x[turn] == false) {
					cnt++;
					if (cnt == m) { goto E; }
				}
				turn++;
				if (turn > n) { turn = 1; }
			}
		E:;
			x[turn] = true;
			remain--;
		}
		for (int i = 1; i <= n; i++) {
			if (x[i] == false) { cout << i << endl; }
		}
	}
}