#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
//#include <tuple>
#include <set>
#include <string.h>
#include <functional>

#define X first
#define Y second
#define MP make_pair
//#define MT make_tuple
#define REP(i, a, n) for(int (i) = (a); (i) < (n); ++(i))
#define FOR(i, n) REP(i, 0, n)
typedef long long ll;
using namespace std;
const int MAX = 500;
const double eps = 0.0000001;

template<class T, class U>
void convert(T &t, U &u)
{
	stringstream ss;
	ss << t;
	ss >> u;
}

int main()
{
	int n, m;
	while( cin >> n >> m && n | m ){
		vector<int> tb(n, 0);
		FOR(i, n){ tb[i] = i; }

		int index = n - 1;
		int ans = -1;
		bool b = false;
		while( !b ){
			FOR(j, m){
				while(1){
					index = ( index + 1 ) % n;
					if( tb[index] != -1 ) break;
				}
			}

			ans = index + 1;
			tb[index] = -1;

			b = true;
			FOR(i, n){ 
				b &= ( tb[i] == -1 ); 
			}
		}

		cout << ans << endl;
	}
	return 0;
}