#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N, M;
	while (cin >> N >> M, !(N == 0 && M == 0)) {
		vector<lint>A(N);
		lint now = N - 1;
		lint cnt1 = 0;
		lint cnt2 = 0;
		while (1){
			
			//cout << now << ' ' << cnt1 << ' ' << cnt2 << endl;
			if (A[now] != -1) {
				cnt1++;
			}
			if (cnt1 == M) {
				A[now] = -1;
				cnt1 = 0;
				cnt2++;
			}
			if (cnt2 == N) {
				cout << now+2 << endl;
				break;
			}
			now++;
			if (now == N) {
				now = 0;
			}
			
			//cout << cnt2 << enld;
		}
	}
}
