#include <iostream>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long

int main()
{
    while (1)
    {
	int n,m,p[1000]={0},tmp=0;
	cin >> n >> m;
	if (n==0)break;
	rep (i,n)
	{
	    rep(j,m)
	    {
		tmp++;
		if (p[tmp%n] != 0)j--;
	    }
	    p[tmp%n]=1;
	}
	(tmp%n == 0)?cout << n:cout << tmp%n;
	cout << endl;
    }
    return 0;
}