#include <iostream>
using namespace std;

int main(){
	const int nmax = 1000;
	int a[nmax], next[nmax];
	int N, M;
	while(cin >> N >> M){
		if(N == 0 && M == 0) break;
		int i = 1;
		for(; i < N; i++){
			a[i] = i; next[i] = i+1;
		}
		a[N] = N;
		next[N] = 1;
		while(next[i] != i){
			for(int j = 1; j < M; j++) i = next[i];
			next[i] = next[next[i]];
		}
		cout << a[i] << endl;
	}
	return 0;
}