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

int main()
{
	int a[1001];
	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;

		rep(i,n)
		{
			if(delete_count == n-1)
			{
				break;
			}

			if(a[i] == 1)
			{
				count++;

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

			if(i == n-1)
			{
				i = -1;
			}
		}

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