#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector<int> Vec;
		Vec.assign(n, 1);
		int count = n;
		int pos = 0;
		int step;
		while(count != 1)
		{
			step = m - 1;
			while(step)
			{
				if(Vec[pos] == 0)
				{
					while(Vec[pos] == 0)
					{
						pos++;
						if(pos == n)
						{
							pos = 0;
						}
					}
				}
				step--;
				pos++;
				if(pos == n)
				{
					pos = 0;
				}
			}
			while(Vec[pos] == 0)
			{
				pos++;
				if(pos == n)
				{
					pos = 0;
				}
			}
			Vec[pos] = 0;
			count--;
			cout << pos + 1<< " " << count << endl;
		}
		for(int i = 0; i < n; ++i)
		{
			if(Vec[i] == 1)
			{
				cout << i + 1<< endl;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}