#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m && n && m) {
		vector<int> p;
		for (int i = 1; i <= n; i++)
			p.push_back(i);
		vector<int>::iterator it = p.begin();
		while (p.size() > 1) {
			for (int i = 1; i < m; i++) {
				it++;
				if (it == p.end())
					it = p.begin();
			}
			it = p.erase(it);
			if (it == p.end())
				it = p.begin();
		}
		cout << p.front() << endl;
	}
	return 0;
}