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

int main(){
	int n, k;
	while(cin >> n >> k, n){
		vector<int> v(n);
		for(int i = 0; i < n; ++i){
			v[i] = i + 1;
		}

		int p = 0;
		while(v.size() > 1){
			p = (p + k - 1) % v.size();
			v.erase(v.begin() + p);
		}
		cout << v[0] << '\n';
	}
}