#include <iostream>
#include <cstring>

using namespace std;

int main()
{
	int n, m;
	int sim[1000];
	
	while( cin >> n >> m, (n||m))
	{
		int cnt = 1, rem = n;
		memset( sim, 0, sizeof(sim));
		
		for(int i = 1 ;  ; i++)
		{
			if( i > n )
				i = 1;
				
			if( sim[i] != 1)
			{
				if( rem == 1 )
				{
					cout << i << endl;
					break;	
				}
				
				if( cnt == m )
				{
					sim[i] = 1;
					cnt = 0;
					rem--;
				}
				
				cnt++;
			}
		}
	}
	
	
	return 0;
}