#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		vector<bool> persons(n, true);

		for(int pos=0, cnt=n; cnt>1; --cnt){
			for(int c=0;; pos = (pos+1)%n){
				c += persons[pos];
				if(c == m)
					break;
			}
			persons[pos] = false;
			pos = (pos+1)%n;
		}

		int ans;
		rep(i, n){
			if(persons[i]){
				ans = i+1;
				break;
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}