#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

bool alive[1005];

int main()
{
//	cut here before submit 
//	freopen ("testcase.josephs_potato", "r", stdin );
	memset (alive, false, sizeof (alive ) );
	int n, m;
	while (scanf ("%d %d", &n, &m ),n ){
		fill (alive, alive + n, true );
		int curr = 0, cnt;
		while ((int)count (alive, alive + n, true ) > 1 ){
			cnt = 1;
			while (cnt < m ){
				while (!alive[curr] ){
					curr = (curr+1)%n;
				}// end while
				cnt++;
				curr = (curr+1)%n;
			} // end while
			while (!alive[curr] ){
				curr = (curr+1)%n;
			} // end while
//			cout << setw(2) << curr << " is dead." << endl;
			alive[curr] = false;
			while (!alive[curr] ){
				curr = (curr+1)%n;
			} // end while
//			cout << setw(2) << curr << " is next start person." << endl;
		} // end while
		cout << curr+1 << endl;
	} // end while	

	return 0;
}