#include<iostream>
#include<cstring>

int n, m;
int dp[1001];

int main()
{
	while( std::cin >> n >> m, n | m )
	{
		memset( dp, 0, sizeof( dp ) );
	
		dp[1] = 0;
		for( int i = 2; i <= n; ++i )
			dp[i] = ( dp[i-1] + m ) % i;

		std::cout << dp[n] + 1 << std::endl;
	}

	return 0;
}