#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>
  
using namespace std;
  
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0)break;
		
		
		vector<int> cand;
		reps(i,1,n+1)cand.push_back(i);
		
		int ind = cand.size()-1;
		
		while(1){
			rep(i,m){
				ind = (ind+1)%cand.size();
			}
			
			//printf("*%d %d\n",ind,cand[ind]);
			cand.erase(cand.begin()+ind);
			
			ind = (ind+cand.size()-1)%cand.size();
			
			if(cand.size()==1){
				printf("%d\n",cand[0]);
				break;
			}
		}
	}
}