import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;

void main(){
    while(true){
	int n,m;
	auto s = split(readln()).to!(int[]);
	n = s[0];
	m = s[1];
	if(n==0&&m==0) break;
	int count;
	int d;
	int i = -1;
	bool[1001] al;
	for(int j=0;j<=1000;j++){
	    al[j] = false;
	}
	while(true){
	    i = (i+1)%n;
	    if(!al[i]) count++;
	    else continue;
	    if(count%m==0){
	       	al[i] = true;
		d++;
	    }
	    if(d==n-1) break;
	}
	for(int j=0;j<n;j++){
	    if(!al[j]) writeln(j+1);
	}
    }
}