#include<iostream>
using namespace std;

int main(){
	int n, m;
	bool *map;
	while( cin >> n >> m, n||m ){
		map = new bool[n];
		int pot = n-1;
		for( int i=0; i<n; i++ )	map[i] = false;
		for( int i=0; i<n-1; i++ ){
			for( int j=0; j<m; j++ ){
				pot++;
				if( pot >= n )	pot -= n;
				if( map[pot] ) j--;
			}
		map[pot] = true;
		}
		for( int i=0; i<n; i++ )
			if( !map[i] )	cout << (i+1) << endl;
		delete[] map;
	}
	return 0;
}