import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main
(String[] args
) { Scanner in
= new Scanner
(System.
in); int n = in.nextInt(), k = in.nextInt();
ArrayList<Integer> ns = new ArrayList<Integer>(n);
for (int i = 1; i <= n; i++)
ns.add(i);
int i = 0, j = 0;
while(n > 1) {
j = (++j) % k;
if(j == 0) {
n--;
ns.remove(i);
} else {
i = (++i) % n;
}
}
System.
out.
println(ns.
get(0)); }
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpwdWJsaWMgY2xhc3MgTWFpbiB7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CgkJU2Nhbm5lciBpbiA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CgkJaW50IG4gPSBpbi5uZXh0SW50KCksIGsgPSBpbi5uZXh0SW50KCk7CgkJQXJyYXlMaXN0PEludGVnZXI+IG5zID0gbmV3IEFycmF5TGlzdDxJbnRlZ2VyPihuKTsKCQlmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIAoJCQlucy5hZGQoaSk7CgkJCgkJaW50IGkgPSAwLCBqID0gMDsKCQl3aGlsZShuID4gMSkgewoJCQlqID0gKCsraikgJSBrOwoJCQlpZihqID09IDApIHsKCQkJCW4tLTsKCQkJCW5zLnJlbW92ZShpKTsKCQkJfSBlbHNlIHsKCQkJCWkgPSAoKytpKSAlIG47CgkJCX0KCQl9CgkJU3lzdGVtLm91dC5wcmludGxuKG5zLmdldCgwKSk7Cgl9Cn0=