#include <iostream>
#include <queue>

using namespace std;

int main()
{
	int n, m;
	
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		queue<int> que;
		for(int i = 1; i <= n; i++){
			que.push(i);
		}
		
		n = 1;
		while(que.size() > 1){
			if(n == m){
				n = 0;
			} else {
				que.push(que.front());
			}
			que.pop();
			n++;
		}
		
		cout << que.front() << endl;
	}
	
	return 0;
}