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

int main() {
	int n,m;
	queue<int> qu;
	while(1){
		cin >> n >> m;
		if(!n && !m) break;
		for(int i = 1;i <= n;i++) qu.push(i);
		int cnt = 0;
		while(qu.front() != qu.back()){
			int buf = qu.front();
			qu.pop();
			qu.push(buf);
			cnt++;
			if(cnt % (m - 1) == 0) {
				qu.pop();
			}
		}
		cout << qu.back() << endl;
		qu.pop();
	}
	return 0;
}