#include <iostream>
using namespace std;
int main(void)
{
	int n,m;
	while(cin >> n >> m){
		if(n==0&&m==0) break;
		int member[1001]={0};
		int count_n=0;
		int first = n;
		while(count_n != n){
			int count_m = 0;
			int i = first;
			while(1){
				if( member[i%n] == 0){
					count_m++;
				}
				if(count_m==m) break;
				i++;
			}
			member[i%n] = 1;
			first = i%n;
			count_n++;
		}
		cout << first+1 << endl;
	}
	return 0;
}