#include <iostream>
using namespace std;

bool circle[1000];
int n, m, c;

void remove(int a, int turn){
	while (c!= 1) {
		int next = (a+1) % n;
		if(circle[a]){
			//cout << a << ',' << turn << endl;
			if (turn == m) {
				//cout << "removing: " << a+1 << endl;
				circle[a] = false;
				c--;
				remove(next, 1);
			}else{
				remove(next, turn+1);
			}
		}else {
			remove(next, turn);
		}
	}
}

int main(){
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		// initialize
		for (int i = 0; i < n; i++) {
			circle[i] = true;
		}
		c= n;
		// main
		//cout << n << endl;
		remove(n-1, 0);
		// output
		for (int i = 0; i < n; i++) {
			if(circle[i]){
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}