#include <stdio.h>
#include <stdlib.h>

typedef struct tag_circle {
	struct tag_circle *next;
	struct tag_circle *prev;
	int value;
} circle;

void rm_circle(circle *target) {
	if(target->next == target->prev)
		target->next->next = target->next->prev = NULL;
	else {
		target->prev->next = target->next;
		target->next->prev = target->prev;
	}
	free(target);
	return;
}

int main() {
	int i;
	int n, m;

	circle *now, *first, *remove;

	do {
		scanf("%d %d", &n, &m);
		if(!n && !m)
			break;

		now = first = (circle*)malloc(sizeof(circle));
		now->next = NULL;
		now->prev = NULL;
		now->value = 1;

		for(i = 1; i < n; i++) {
			now->next = (circle*)malloc(sizeof(circle));
			now->next->prev = now;
			now = now->next; /* nowのさすアドレス変更 */
			now->next = NULL;
			now->value = i + 1;
		}

		now->next = first;
		first->prev = now;

		now = first;
		i = 1;
		while(now->next != NULL) {
			if(i % m == 0) {
				remove = now;
				now = now->next;
				rm_circle(remove);
			}

			else
				now = now->next;
			i++;
		}

		free(now);

		printf("%d\n", now->value);
	} while(1);

	return 0;
}