#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	int a[1000];
	int n,m;
	while(cin >> n >> m && n && m)
	{
		rep(i,n)
		{
			a[i] = 1;
		}
		int i = 0;
		int count = 0;
		int delete_count = 0;
		while(1)
		{
			if(delete_count == n-1)
			{
				break;
			}

			if(a[i] == 1)
			{
				if(count == m)
				{
					a[i] = 0;
					delete_count++;
					count = 1;
				}
				else
				{
					count++;
				}

				if(i == n-1)
				{
					i = 0; 
				}
				else
				{
					i++;
				}
			}
			else
			{
				if(i == n-1)
				{
					i = 1;
				}
				else
				{
					i++;
				}
			}
		}
	
		rep(i,n)
		{
			if(a[i] == 1)
			{
				if(i == 0)
				{
					cout << n << endl;
				}
				else
				{
					cout << i << endl;
				}
			}
			
		}
		
	}
	return 0;
}