#include <bits/stdc++.h>
#include "findposition.h"
using namespace std;
const int MAXN = 8e4;
int n, k;
int t[4 * MAXN];
void build(int v, int tl, int tr)
{
if (tl == tr) {
t[v] = tl;
}
else {
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
t[v] = (IsLess(t[v * 2] + 1, t[v * 2 + 1] + 1) ? t[v * 2] : t[v * 2 + 1]);
}
}
void update(int v, int tl, int tr, int pos)
{
if (tl == tr) {
t[v] = -1;
}
else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v * 2, tl, tm, pos);
else
update(v * 2 + 1, tm + 1, tr, pos);
if (t[v * 2] == -1 && t[v * 2 + 1] == -1)
t[v] = -1;
else if (t[v * 2] == -1)
t[v] = t[v * 2 + 1];
else if (t[v * 2 + 1] == -1)
t[v] = t[v * 2];
else
t[v] = (IsLess(t[v * 2] + 1, t[v * 2 + 1] + 1) ? t[v * 2] : t[v * 2 + 1]);
}
}
int main()
{
Init(n, k);
build(1, 0, n - 1);
for (int i = 0; i < k - 1; i++) {
update(1, 0, n - 1, t[1]);
}
Finish(t[1] + 1);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlICJmaW5kcG9zaXRpb24uaCIKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIApjb25zdCBpbnQgTUFYTiA9IDhlNDsKIAppbnQgbiwgazsKaW50IHRbNCAqIE1BWE5dOwogCnZvaWQgYnVpbGQoaW50IHYsIGludCB0bCwgaW50IHRyKQp7CiAgICBpZiAodGwgPT0gdHIpIHsKICAgICAgICB0W3ZdID0gdGw7CiAgICB9CiAgICBlbHNlIHsKICAgICAgICBpbnQgdG0gPSAodGwgKyB0cikgLyAyOwogICAgICAgIGJ1aWxkKHYgKiAyLCB0bCwgdG0pOwogICAgICAgIGJ1aWxkKHYgKiAyICsgMSwgdG0gKyAxLCB0cik7CiAgICAgICAgdFt2XSA9IChJc0xlc3ModFt2ICogMl0gKyAxLCB0W3YgKiAyICsgMV0gKyAxKSA/IHRbdiAqIDJdIDogdFt2ICogMiArIDFdKTsKICAgIH0KfQogCnZvaWQgdXBkYXRlKGludCB2LCBpbnQgdGwsIGludCB0ciwgaW50IHBvcykKewogICAgaWYgKHRsID09IHRyKSB7CiAgICAgICAgdFt2XSA9IC0xOwogICAgfQogICAgZWxzZSB7CiAgICAgICAgaW50IHRtID0gKHRsICsgdHIpIC8gMjsKICAgICAgICBpZiAocG9zIDw9IHRtKQogICAgICAgICAgICB1cGRhdGUodiAqIDIsIHRsLCB0bSwgcG9zKTsKICAgICAgICBlbHNlCiAgICAgICAgICAgIHVwZGF0ZSh2ICogMiArIDEsIHRtICsgMSwgdHIsIHBvcyk7CiAgICAgICAgaWYgKHRbdiAqIDJdID09IC0xICYmIHRbdiAqIDIgKyAxXSA9PSAtMSkKICAgICAgICAgICAgdFt2XSA9IC0xOwogICAgICAgIGVsc2UgaWYgKHRbdiAqIDJdID09IC0xKQogICAgICAgICAgICB0W3ZdID0gdFt2ICogMiArIDFdOwogICAgICAgIGVsc2UgaWYgKHRbdiAqIDIgKyAxXSA9PSAtMSkKICAgICAgICAgICAgdFt2XSA9IHRbdiAqIDJdOwogICAgICAgIGVsc2UKICAgICAgICAgICAgdFt2XSA9IChJc0xlc3ModFt2ICogMl0gKyAxLCB0W3YgKiAyICsgMV0gKyAxKSA/IHRbdiAqIDJdIDogdFt2ICogMiArIDFdKTsKICAgIH0KfQogCmludCBtYWluKCkKewogICAgSW5pdChuLCBrKTsKICAgIGJ1aWxkKDEsIDAsIG4gLSAxKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgayAtIDE7IGkrKykgewogICAgICAgIHVwZGF0ZSgxLCAwLCBuIC0gMSwgdFsxXSk7CiAgICB9CiAgICBGaW5pc2godFsxXSArIDEpOwogICAgcmV0dXJuIDA7Cn0=