#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;

int main()
{
	while (true)
	{
		int n, m;
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0)
			break;

		bool p[1000];
		fill(p, p+n, true);
		for (int i = 0, c = 0, esc = 0; ; ++i)
		{
			if (i == n)
				i = 0;
			if (p[i])
			{
				if (++c % m == 0)
				{
					p[i] = false;
					if (++esc == n)
					{
						printf("%d\n", i+1);
						break;
					}
				}
			}
		}
	}

	return 0;
}