import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    foreach(s;stdin.byLine())
    {
        auto nm = s.split().map!(to!int);
        immutable n=nm[0], m=nm[1];
        if(n==0 && m==0) break;
        auto a = iota(1,n+1).array();
        size_t p=n-1;
        while(a.length>1)
        {
            p=(p+m)%a.length;
            a=a[0..p]~a[p+1..$];
            p=p<=0?a.length-1:p-1;
        }
        writeln(a[0]);
    }
}