#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

int solve(int n,int m){
	//int hu[n+1];
	queue<int> q;
	queue<int> tmp;
	//int pos=m;
	int num=n;
	int i;
	//memset(hu,0,sizeof(hu));
	for(i=1;i<=n;i++){
		q.push(i);
	}
	while(num!=1){
		int tmp1 = m;
		while(num<tmp1) tmp1-=num;
		//hu[pos]=1;
		for(i=1;i<tmp1;i++){
			tmp.push(q.front());
			//cout<<q.front()<<endl;
			q.pop();
		}
		//cout<<"pop = "<<q.front()<<endl;
		q.pop();
		for(i=1;i<tmp1;i++){
			q.push(tmp.front());
			tmp.pop();
		}
		
		num--;
		//pos+=m;
		/*while(pos>n) pos-=n;
		while(hu[pos]==1){
			if(pos==n) pos=1;
			else pos++;
		}*/
		//cout<<"num = "<<n-num<<endl<<endl;
		
		
	}
	cout<<q.front()<<endl;
	return 0;
}
	



int main(){
	int n,m;
	
	
	cin>>n>>m;
	while(!(n==0&&m==0)){
		solve(n,m);
		cin>>n>>m;
	}
	return 0;
}