#include<cstdio>
#include<iostream>
using namespace std;
int n,m;
int func(int a){
	return a%n?a%n:n;
}
int main(){
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0)break;
		int temp = 0;
		bool flg[1001] = {false};
		for(int i = 1; i < n; i++){
			for(int j = 0; j < m; j++){
				temp++;
				if(flg[func(temp)] == false);
				else j--;
			}
			flg[func(temp)] = true;
		}
		for(int i = 1; i <= n; i++)if(flg[i] == false)cout << i << endl;
	}
	return 0;
}