#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int f[1000],m,n,p,c,i;
	while(cin >> n >> m) {
		if (n+m==0) break;
		for (i=0;i<n;i++) f[i]=0;
		p=n-1;
		for (i=0;i<n;i++) {
			c=0; 
			while(true) {
				p=(p+1) % n;
				if (f[p]==0) {c++; if (c==m) { f[p]=1; break;}}
			}
		}
		cout << p+1 << endl;
     }
    return 0;
}