#include<stdio.h>
int main()
{
	int m,n;
	while(scanf("%d%d",&n,&m),n)
	{
		bool isLose[1000] = {false};
		int i = 0, loseCount = 0, count = 0;
		while(loseCount<n-1)
		{
			if(!isLose[i])
			{
				if(++count==m)
					isLose[i]=true, count=0,++loseCount;
			}
			i = (i+1)%n;
		}
		for(i=0;i<n;i++)
			if(!isLose[i])
				printf("%d\n",i+1);
	}
	return 0;
}