#include <iostream>
#include <sstream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main(){
	int n,m;
	while(1){
		cin >> n >> m;
		if(n+m==0) break;
		bool a[n];
		for(int i=0;i<n;i++) a[i] = false;
		int b = 0;
		for(int i=0;i<n-1;i++){
			int c = 0;
			for(int j=0;;j++){
				int d = (b+j)%n;
				if(a[d]) continue;
				c++;
				if(c==m){
					a[d] = true;
					b = d;
					break;
				}
			}
		}
		for(int i=0;i<n;i++) if(not a[i]) cout << i+1 << endl;
	}
}