#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for (int n, m; cin >> n >> m&&n;) {
		vector<bool> out(n);
		int imo = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m;) {
				if (!out[(++imo) %= n])
					j++;
			}
			out[imo] = true;
			if (imo == 0)imo = n;
		}
		cout << imo << endl;
	}
	return 0;
}