#include <iostream>
using namespace std;

int main(){
	int n,m,count,tmp;
	while(cin >> n >> m && n && m){
		bool flag[n+1];
		count = 0;
		for(int i = 1;i <= n;++i){
			flag[i] = true;
		}
		tmp = m;
		for(int i = 1;i <= n;++i){
			if(count == (n - 1)) break;
			if(flag[i]){
				--tmp;
				if(tmp == 0){
					flag[i] = false;
					count++;
					tmp = m;
				}
			}
			if(i == n) i = 0;
		}
		for(int i = 1;i <= n;++i){
			if(flag[i]){
				cout << i << endl;
			}
		}

	}
	return 0;
}