#include <iostream>

int main(){
	int n, m;
	int participant[1001];
	while(std::cin >> n>>m, n+m){
		int begin=1;
		int dummy = 0;
		for(int i=0;i<=n;++i)participant[i]=1;
		while(1){
			int cnt=0;
			A:;
			int coun = 0;
			for(int i = 1; i <= n; ++i)coun += participant[i];
			if(coun == 1){
				break;
			}
			for(int j=(begin!=1?begin:1);j<=n;++j){
				cnt += participant[j];
				if(cnt==m){
					participant[j]=0;
					begin=j;
					//std::cout<<j<<std::endl;
					break;
				}
				begin=1;
			}
			if(cnt!=m)goto A;
		}
		for(int i=1;i<=n;++i){
			if(participant[i])std::cout<<i<<std::endl;
		}
	}
}