#include <iostream>
#include <vector>

using namespace std;

int main(void){
	int n, m, i, p;
	vector<int> v;
	while(1){
		cin >> n >> m;
		if((n | m) == 0){
			break;
		}
		for(i = 0;i < n;i++){
			v.push_back(i + 1);
		}
		p = 0;
		while(v.size() > 1){
			p = (p + m - 1) % v.size();
			for(i = p;i < v.size() - 1;i++){
				v[i] = v[i + 1];
			}
			v.pop_back();
			p %= v.size();
		}
		printf("%d\n",v[0]);
		v.clear();
	}
	return 0;
}