#include<iostream>
using namespace std;
int main(){
	int n,m;
	while(cin >>n>>m){
		if(!n && !m){break;}
		bool potato[1000] = {0};
		int p = 0, x;
		for(int i=0; i<n; i++){
			x = m;
			for(;;p++){
				if(!potato[p]){x--;}
				if(!x){potato[p] = true;break;}
				if(p>=n){p-=n;}
			}
		}
		cout<<p+1<<endl;
	}
	return 0;
}