# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	int m, n;
	while (cin >> n >> m&&n) {
		vector<int> v;
		for (int i = 1; i <= n; i++) {
			v.emplace_back(i);
		}
		int pos = 0;
		while (v.size() != 1) {
			pos += m-1;
			if (pos >= v.size())pos %= v.size();
			v.erase(v.begin() + pos);
		}
		cout << v[0] << endl;
	}
}