#include <iostream>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m){
		if(m==0&&n==0)break;
		bool pp[1001];
		for(int i=0;i<n;++i)pp[i]=true;
		for(int i=0,count=0,erase_count=0;erase_count<n-1;i=(i+1)%n){
			if(!pp[i])continue;
			if(count%m==0&&count!=0){
				pp[i]=false;
				erase_count++;
			}
			++count;
		}
		for(int i=0;i<n;++i)if(pp[i])cout<<((i==0)?n:i)<<"\n";
	}
	return 0;
}