#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n, m;
	while(cin >> n >> m && (n || m)) {
		bool a[1000+10] = {};
		int cnt = 0;
		int i = 0;
		rep(j,n) {
			while(1) {
				if(!a[i%n+1]) {
					cnt++;
					if(cnt == m) break;
				}
				i++;
			}
			cnt = 0;
			a[i%n+1] = 1;
			i++;
		}
		int ret = (i % n == 0) ? n : (i % n);
		cout << ret << endl;
	}
	return 0;
}