#define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 1000
#define MIN 2
int main(void)
{
	int n, m;
	while (scanf_s("%d %d",&n,&m) != EOF) {
		if (n == 0 && m == 0) break;
		int h[MAX + 1] = { 0 },ans = 0, cou = 0, k = 0;
		while(cou < n) {
			for (int i = ans + 1; k <= m; ++i) {
				if (i > n) { i = i - n; }
				if (h[i] == false) { ++k; }
				if (k >= m) {
					k = 0; ++cou;
					h[i] = true;
					ans = i;
					break;
				}
			}
		}
		printf("%d\n", ans);
	}
}