#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){

	int n,m,count,tmp_count;

	while(true){
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0)break;

		count = n;
		int array[n];
		for(int i=0; i < n; i++)array[i] = 1;

		tmp_count = 0;
		for(int i=0;count > 1;){
			if(array[i] == 1){
				tmp_count++;
				if(tmp_count == m){
					array[i] = 0;
					count--;
					tmp_count = 0;
					i = (i+1)%n;
				}else{
					i = (i+1)%n;
				}
			}else{
				i = (i+1)%n;
			}
		}

		for(int i=0; i < n; i++){
			if(array[i] == 1)printf("%d\n",i+1);
		}

	}

    return 0;
}