#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;
}