#include<iostream>
using namespace std;
int n,m;
int d[1000];
main()
{
	while(cin>>n>>m,n)
	{
		for(int i=0;i<n;i++)d[i]=0;
		int cnt=0,pos=0;
		while(cnt<n)
		{
			int now=0;
			while(now<m)
			{
				if(!d[pos%n])now++;
				pos++;
			}
			d[(pos-1)%n]=1;
			cnt++;
		}
		cout<<(pos-1)%n+1<<endl;
	}
}

