#include <bits/stdc++.h>
#define range(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)
using namespace std;

int n,m;

bool on[1010];

int main(void){
	while(cin >> n >> m,n){
		rep(i,n) on[i]=true;
		int ans=0;
		int cur=n-1;
		rep(i,n){
			rep(loop,m){
				cur=(cur+1)%n;
				while(!on[cur]) cur=(cur+1)%n;
			}
			on[cur]=false;
			ans=cur+1;
		}
		cout << ans << endl;
	}
	return 0;
}