#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int n,m;
	while(cin >> n >> m){
		if(n==0 && m==0 || cin.eof()) break;
		vector< int> cr(n);
		rep(i,n) cr[i]=i+1;
		int sta =0;
		while(1){
			int zn = cr.size();
//			rep(z,zn) cout << cr[z] << " "; cout << endl;
			if(zn==1) break;
			int ar = (sta + m -1 ) % zn ;
			cr.erase(cr.begin()+ar);
			sta = ar;
		}
		cout << cr[0] << endl;
	
	}
	return 0;
	
}