#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;

int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(!(n&&m))break;
		bool num[n+1];
		rep(i,n+1)num[i]=true;
		num[0]=false;
		int now=0,cnt=0,ans;
		while(1){
			now++;
			if(now>n)now-=n;
			if(!num[now])continue;
			else cnt++;
			if(cnt==m){
				num[now]=false;
				cnt=0;
			}
			int check=0;
			loop(i,1,n+1)if(num[i])check++;
			if(check==1)break;
		}
		loop(i,1,n+1)if(num[i]){ans=i;break;}
		cout<<ans<<endl;
	}
	return 0;
}