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

int main(){
	
	int n, m, now;
	vector<int> vc;

	while(cin >> n >> m){
		vc.clear();
		if(n == 0) break;
		for(int i=0; i<n; i++){
			vc.push_back(i);
		}

		now = 0;
		while(vc.size()){
			now = (now + m-1) % (vc.size());
			vc.erase(vc.begin() + now);
/*			
			for(int i=0; i<n; i++){
				cout << vc[i] << " ";
			}
			cout << "[" << now << "]" << n << endl;
*/		}
	
		cout << vc[0]+1 << endl;
	}
	
	return 0;
	
}