#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>

#define REP(i,n) for(int i=0;i<n;i++)
#define PI 3.14159265359

#define INF 1000000;

using namespace std;


int main()
{
	int n, m;
	
	while (scanf("%d %d\n", &n, &m), n && m)
	{
		vector<int> v;
		for (int i=1; i<=n; i++) v.push_back(i);
		vector<int>::iterator it = v.begin();
		while (1 < v.size())
		{
			for (int i=1; it = it == v.end() ? v.begin() : it, i < m; i++)
			{
				it++;
			}
			it = v.erase(it);
		}
		printf("%d\n", v[0]);
	}
	
	/*
    REP(i, 10)
	{
    	cout << i << '\n';
	}
	*/
	
	return 0;
}