#include<stdio.h>
#include<queue>
using namespace  std;
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		queue<int>Q;
		for(int i=0;i<a;i++)Q.push(i+1);
		int now=1;
		while(Q.size()>1){
			int t=Q.front();
			if(now%b!=0){
				Q.push(t);
			}
			now++;
			Q.pop();
		}
		printf("%d\n",Q.front());
	}
}