#include <stdio.h>
#include <iostream>

using namespace std;

int main() {

	int hito[1000];
	int m,n;
	int a;
	int counter = 0;
	int counter2 = 0;
	int k = 0;

	while (1) {
		cin >> n >> m;

		if (n == 0 && m == 0) {
			break;
		}

		for (int i = 0; i < n; i++) {
			hito[i] = 1;
		}

		while (1) {
			if (hito[k] == 1) {
				counter++;
			}

			if (counter == m) {
				hito[k] = 0;
				counter = 0;
				counter2++;
			}

			if (counter2 == n){
				cout << k + 1 << endl;
				break;
			}

			k++;

			if (k >= n) {
				k = 0;
			}
		}
	}

	return 0;
}