#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int n, m;
	while (cin >> n >> m, n) {
		vector<int>v;
		rep(i, n)v.push_back(i + 1);
		int cnt = 0;
		while (1) {
			if (v.size() == 1)break;
			v.erase(v.begin() + (cnt + m - 1) % v.size());
			cnt = (cnt + m - 1) % (v.size() + 1);
		}
		cout << v[0] << endl;
	}
}