#include<iostream>
#include<vector>

using namespace std;

int main(void){
	
	while( true ){
		unsigned int potato = 0;
		int n, m;
		vector<int> vpeople;

		cin >> n >> m;
		if( n == 0 && m == 0 ) break;

		for(int i = 0; i < n; i++) vpeople.push_back( i + 1 );

		while( vpeople.size() > 1 ){
			potato += m-1;
			potato %= vpeople.size();
			vpeople.erase(vpeople.begin()+potato);
		}
		cout << vpeople[0] << endl;
	}
}