#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	int n, m;
	while (cin >> n >> m)
	{
		if (n == 0 && m == 0)
		{
			break;
		}

		set<int> p;

		for (int i = 0; i < n; i++)
		{
			p.insert(i);
		}

		int s = -1;
		while (p.size() > 1)
		{
			for (int j = 0; j < m;)
			{
				s = (s + 1) % n;
				if (p.count(s))
				{
					j++;
				}
			}
			p.erase(s);
		}

		for (int i = 0; i < n; i++)
		{
			if (p.count(i))
			{
				cout << i + 1 << endl;
			}
		}
	}
}
