#include <iostream>
using namespace std;

int main(){
	int n, m;

	while ( cin >> n >> m && ( n || m ) ){
		bool* man = new bool[ n ]();
		int p = n - 1;
		for ( int i = 0; i < n - 1; ++i ){
			int cnt = 0;
			while( cnt != m ){
				p = ( p + 1 ) % n;
				if ( !man[ p ] ){
					++cnt;
				}
			}
			man[ p ] = true;
		}

		for ( int i = 0; i < n; ++i ){
			if ( !man[ i ] ){
				cout << i + 1 << endl;
				break;
			}
		}

		delete[] man;
	}
	return 0;
}