#include <iostream>
using namespace std;

int main(){
	int n,m;
	int *potato;
	int count, pos;
	while(cin>>n>>m,n||m){
		potato = new int[n];
		for(int i=0;i<n;++i)potato[i]=1;
		pos = 0;
		for(int i=0;i<n;++i){
			count = 0;
			while(1){
				if(potato[pos])count++;
				if(count == m){
					potato[pos] = 0;
					break;
				}
				pos = (pos+1)%n;
			}
		}
		cout<<pos+1<<endl;
	}
	return 0;
}