
import std.stdio, std.typecons;

alias Tuple!(int, "from", int, "to", int, "value") Number;

void main() {
  int size, interval;
  while(readf("%d %d\n", &size, &interval), (size + interval) != 0) {
    Number[int] table;

    for(int i = 2; i < size; i++) {
      table[i] = Number(i - 1, i + 1, i);
    }
    table[1] = Number(size, 2, 1);
    table[size] = Number(size - 1, 1, size);

    int m = size;
    int len = 0;
    while(table.length != 1) {
      if (len == interval) {
        int to = table[m].to;
        int from = table[m].from;
        table.remove(m);
        table[from].to = to;
        table[to].from = from;
        m = to;
        len = 0;
      }
      else {
        m = table[m].to;
      }
      len++;
    }
    writeln(m);
  }
}