import std.stdio,std.string,std.conv;

int main()
{
	string s;
	int a[1001];
	while((s = readln.chomp).length != 0)
	{
		string[] _s = s.split(" ");
		int n = _s[0].to!int;
		int m = _s[1].to!int;

		if(n == 0 && m == 0)
		{
			break;
		}

		foreach(i;0..n)
		{
			a[i] = 1;
		}

		int count = 0;
		int delete_count = 0;

		for(int i=0; i < n ; i++)
		{
			if(delete_count == n-1)
			{
				break;
			}
			
			if(a[i] == 1)
			{
				count++;
				
				if(count == m)
				{
					a[i] = 0;
					count = 0;
					delete_count++;
				}
			}
			
			if(i == n-1)
			{
				i = -1;
			}
		}

		foreach(i;0..n)
		{
			if(a[i] == 1)
			{
				(i+1).writeln;
			}
		}
	}
	return 0;
}