#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;


int n, m;
int k = 0;


int calc(vi v){
	/*rep(i, v.size()){
		printf("%2d ", v[i]);
	}
	cout << endl;*/
	if (v.size() == 1)return v[0];
	vi v2;
	rep(i, v.size() - 1){
		v2.pb(v[(m + i) % v.size()]);
	}
	return calc(v2);
}

int main(){
	while (cin >> n >> m){
		if (n == 0 && m == 0)break;
		vi v(n);
		rep(i, n){
			v[i] = i + 1;
		}
		cout << calc(v) << endl;
	}
}