#include<iostream>
#include<string>
using namespace std;
bool a[1000];
int main(){
	int n,m;
	while(true){
	cin>>n>>m;
	if(n==0&&m==0)
		break;
	for(int i=0;i<n;i++)
		a[i]=true;
	int b=0,c=0,count=n;
	while(true){
		if(a[b]==true)
			c++;
		if(c==m){
			a[b]=false;
			c=0;
			count--;
		}
		if(count==0)
			break;
		b++;
		b%=n;
	}
	cout<<b+1<<endl;
	}
	return 0;
}