#include <iostream>

struct Node{
	Node *prev, *next;
	int num;
};

int main(){
	while(true){
		int n, m, cnt;
		Node node[1002];

		std::cin >> n >> m;
		cnt = n;
		
		if(n == 0 && m == 0)break;
	
		for(int i = 1; i <= n; i++){
			node[i].next = &node[i + 1];
			node[i].prev = &node[i - 1];
	
			if(i == 1)node[i].prev = &node[n];
			if(i == n)node[i].next = &node[1];
			node[i].num = i;
		}

		Node *now = &node[1];
		int i = 1;
		while(cnt > 1){
			if(i == m){
				now -> prev -> next = now -> next;
				now -> next -> prev = now -> prev;
				i = 1;
				cnt--;
			}
			else i++;
		
			now = now -> next;
		}

		std::cout << now -> num << std::endl;
	}

	return 0;
}