#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){

	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0)){
		vector<int> v;
		for(int i = 1; i <= n; i++)
			v.push_back(i);
		int cp=0;
		m--;
		while(1){
			if(v.size()==1)
				break;
			else{
				int nidx=(cp+m)%(v.size());
				cp=nidx;
				vector<int> nv;
				for(int i = 0; i < v.size(); i++){
					if(i!=nidx){
						nv.push_back(v[i]);
					}
				}
				if(nidx==v.size()-1)
					nidx=1;

				v=nv;
			}
		}
		cout<<v[0]<<endl;
	}

	return 0;
}