#include <bits/stdc++.h>
using namespace std;
unsigned long long findLevel(unsigned long long N, unsigned long long n) {
  unsigned long long curLevel = 0;
  unsigned long long add2 = 1;
  unsigned long long placed = 0;
  while (placed < n) {
    placed += add2;
    add2 = add2 * 2;
    curLevel++;
  }
  return curLevel - 1;
}
bool cruelCase(unsigned long long N, unsigned long long n) {
  unsigned long long curSCnt = 1;
  unsigned long long curBCnt = 0;
  unsigned long long SLen = N;
  unsigned long long add2 = 1;
  unsigned long long placed = 0;
  while (SLen > 3) {
    if (SLen % 2 == 1) {
      curBCnt = curBCnt * 2 + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    placed += add2;
    add2 *= 2;
  }
  if (SLen == 3 && placed + curBCnt < n) return 1;
  if (SLen != 3 && placed < n) return 1;
  return 0;
}
unsigned long long cruelLevelCnt(unsigned long long N, unsigned long long n) {
  unsigned long long curSCnt = 1;
  unsigned long long curBCnt = 0;
  unsigned long long SLen = N;
  unsigned long long add2 = 1;
  unsigned long long placed = 0;
  while (SLen > 3) {
    if (SLen % 2 == 1) {
      curBCnt = curBCnt * 2 + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    placed += add2;
    add2 *= 2;
  }
  if (SLen == 3) return n - placed - curBCnt;
  return n - placed;
}
unsigned long long cruelCnt(unsigned long long len) {
  unsigned long long curSCnt = 1;
  unsigned long long curBCnt = 0;
  unsigned long long SLen = len;
  unsigned long long add2 = 1;
  unsigned long long placed = 0;
  while (SLen > 3) {
    if (SLen % 2 == 1) {
      curBCnt = curBCnt * 2 + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    placed += add2;
    add2 *= 2;
  }
  if (SLen == 3) return len - 1 - placed - curBCnt;
  return len - 1 - placed;
}
unsigned long long findLevelCnt(unsigned long long level,
                                unsigned long long n) {
  unsigned long long curLevel = 0;
  unsigned long long add2 = 1;
  unsigned long long cnt = 0;
  while (curLevel < level) {
    cnt += add2;
    add2 = add2 * 2;
    curLevel += 1;
  }
  return n - cnt;
}
unsigned long long cntBOnLvl(unsigned long long len, bool isBig,
                             unsigned long long curLvl,
                             unsigned long long onLvl) {
  unsigned long long curSCnt = !isBig;
  unsigned long long curBCnt = isBig;
  unsigned long long SLen = len - (isBig);
  unsigned long long ans = isBig && (len % 1 == 0);
  while (curLvl < onLvl) {
    if (SLen % 2 == 1) {
      curBCnt = curBCnt * 2 + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    curLvl++;
  }
  if (SLen % 2 == 1)
    return curBCnt;
  else
    return 0;
}
unsigned long long cntSOnLvl(unsigned long long len, bool isBig,
                             unsigned long long curLvl,
                             unsigned long long onLvl) {
  unsigned long long curSCnt = !isBig;
  unsigned long long curBCnt = isBig;
  unsigned long long SLen = len - (isBig);
  unsigned long long ans = isBig && (len % 1 == 0);
  while (curLvl < onLvl) {
    if (SLen % 2 == 1) {
      curBCnt = (curBCnt * 2) + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    curLvl++;
  }
  if (SLen % 2 == 1)
    return curSCnt;
  else
    return curSCnt + curBCnt;
}
unsigned long long findSol(unsigned long long N, unsigned long long n) {
  unsigned long long level = findLevel(N, n);
  unsigned long long levelCnt = findLevelCnt(level, n);
  unsigned long long levelfBCnt = cntBOnLvl(N, false, 0, level);
  unsigned long long left = 0;
  unsigned long long right = N;
  if (cruelCase(N, n)) {
    long long lvl = 0;
    levelCnt = cruelLevelCnt(N, n);
    while (right - left > 3) {
      lvl++;
      unsigned long long leftLen = (right - left) / 2;
      unsigned long long rightLen = (right - left) - (right - left) / 2;
      unsigned long long leftCnt = cruelCnt(leftLen);
      unsigned long long rigthCnt = cruelCnt(rightLen);
      if (leftCnt < levelCnt) {
        levelCnt = levelCnt - leftCnt;
        left = left + (right - left) / 2;
      } else {
        levelCnt = levelCnt;
        right = left + (right - left) / 2;
      }
    }
    return left + levelCnt + 1;
  } else {
    if (levelfBCnt >= levelCnt) {
      unsigned long long curLvl = 0;
      unsigned long long curS = (right - left);
      while (curLvl < level) {
        curLvl++;
        curS = curS / 2;
        unsigned long long leftLen = (right - left) / 2;
        unsigned long long rightLen = (right - left) - (right - left) / 2;
        unsigned long long leftFB =
            cntBOnLvl(leftLen, leftLen != curS, curLvl, level);
        unsigned long long rightFB =
            cntBOnLvl(rightLen, rightLen != curS, curLvl, level);
        if (leftFB < levelCnt) {
          levelCnt = levelCnt - leftFB;
          left = left + (right - left) / 2;
        } else {
          levelCnt = levelCnt;
          right = left + (right - left) / 2;
        }
      }
    } else {
      levelCnt = levelCnt - levelfBCnt;
      unsigned long long curLvl = 0;
      unsigned long long curS = (right - left);
      while (curLvl < level) {
        curLvl++;
        curS = curS / 2;
        unsigned long long leftLen = (right - left) / 2;
        unsigned long long rightLen = (right - left) - (right - left) / 2;
        unsigned long long leftS =
            cntSOnLvl(leftLen, leftLen != curS, curLvl, level);
        unsigned long long rightS =
            cntSOnLvl(rightLen, rightLen != curS, curLvl, level);
        if (leftS < levelCnt) {
          levelCnt = levelCnt - leftS;
          left = left + (right - left) / 2;
        } else {
          levelCnt = levelCnt;
          right = left + (right - left) / 2;
        }
      }
    }
    return left + (right - left) / 2 + 1;
  }
}
int main() {
  unsigned long long N;
  unsigned long long n;
  cin >> N >> n;
  if (n == 1) {
    cout << 1;
    return 0;
  }
  if (n == 2) {
    cout << N;
    return 0;
  }
  n = n - 2;
  N = N - 1;
  cout << findSol(N, n) << endl;
  return 0;
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

It's been long after the events of the previous problems, and Karen has now moved on from student life and is looking to relocate to a new neighborhood.

<image>

The neighborhood consists of n houses in a straight line, labelled 1 to n from left to right, all an equal distance apart.

Everyone in this neighborhood loves peace and quiet. Because of this, whenever a new person moves into the neighborhood, he or she always chooses the house whose minimum distance to any occupied house is maximized. If there are multiple houses with the maximum possible minimum distance, he or she chooses the leftmost one.

Note that the first person to arrive always moves into house 1.

Karen is the k-th person to enter this neighborhood. If everyone, including herself, follows this rule, which house will she move into?

Input

The first and only line of input contains two integers, n and k (1 ≤ k ≤ n ≤ 1018), describing the number of houses in the neighborhood, and that Karen was the k-th person to move in, respectively.

Output

Output a single integer on a line by itself, the label of the house Karen will move into.

Examples

Input

6 4


Output

2


Input

39 3


Output

20

Note

In the first test case, there are 6 houses in the neighborhood, and Karen is the fourth person to move in:

  1. The first person moves into house 1. 
  2. The second person moves into house 6. 
  3. The third person moves into house 3. 
  4. The fourth person moves into house 2. 



In the second test case, there are 39 houses in the neighborhood, and Karen is the third person to move in:

  1. The first person moves into house 1. 
  2. The second person moves into house 39. 
  3. The third person moves into house 20. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
unsigned long long findLevel(unsigned long long N, unsigned long long n) {
  unsigned long long curLevel = 0;
  unsigned long long add2 = 1;
  unsigned long long placed = 0;
  while (placed < n) {
    placed += add2;
    add2 = add2 * 2;
    curLevel++;
  }
  return curLevel - 1;
}
bool cruelCase(unsigned long long N, unsigned long long n) {
  unsigned long long curSCnt = 1;
  unsigned long long curBCnt = 0;
  unsigned long long SLen = N;
  unsigned long long add2 = 1;
  unsigned long long placed = 0;
  while (SLen > 3) {
    if (SLen % 2 == 1) {
      curBCnt = curBCnt * 2 + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    placed += add2;
    add2 *= 2;
  }
  if (SLen == 3 && placed + curBCnt < n) return 1;
  if (SLen != 3 && placed < n) return 1;
  return 0;
}
unsigned long long cruelLevelCnt(unsigned long long N, unsigned long long n) {
  unsigned long long curSCnt = 1;
  unsigned long long curBCnt = 0;
  unsigned long long SLen = N;
  unsigned long long add2 = 1;
  unsigned long long placed = 0;
  while (SLen > 3) {
    if (SLen % 2 == 1) {
      curBCnt = curBCnt * 2 + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    placed += add2;
    add2 *= 2;
  }
  if (SLen == 3) return n - placed - curBCnt;
  return n - placed;
}
unsigned long long cruelCnt(unsigned long long len) {
  unsigned long long curSCnt = 1;
  unsigned long long curBCnt = 0;
  unsigned long long SLen = len;
  unsigned long long add2 = 1;
  unsigned long long placed = 0;
  while (SLen > 3) {
    if (SLen % 2 == 1) {
      curBCnt = curBCnt * 2 + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    placed += add2;
    add2 *= 2;
  }
  if (SLen == 3) return len - 1 - placed - curBCnt;
  return len - 1 - placed;
}
unsigned long long findLevelCnt(unsigned long long level,
                                unsigned long long n) {
  unsigned long long curLevel = 0;
  unsigned long long add2 = 1;
  unsigned long long cnt = 0;
  while (curLevel < level) {
    cnt += add2;
    add2 = add2 * 2;
    curLevel += 1;
  }
  return n - cnt;
}
unsigned long long cntBOnLvl(unsigned long long len, bool isBig,
                             unsigned long long curLvl,
                             unsigned long long onLvl) {
  unsigned long long curSCnt = !isBig;
  unsigned long long curBCnt = isBig;
  unsigned long long SLen = len - (isBig);
  unsigned long long ans = isBig && (len % 1 == 0);
  while (curLvl < onLvl) {
    if (SLen % 2 == 1) {
      curBCnt = curBCnt * 2 + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    curLvl++;
  }
  if (SLen % 2 == 1)
    return curBCnt;
  else
    return 0;
}
unsigned long long cntSOnLvl(unsigned long long len, bool isBig,
                             unsigned long long curLvl,
                             unsigned long long onLvl) {
  unsigned long long curSCnt = !isBig;
  unsigned long long curBCnt = isBig;
  unsigned long long SLen = len - (isBig);
  unsigned long long ans = isBig && (len % 1 == 0);
  while (curLvl < onLvl) {
    if (SLen % 2 == 1) {
      curBCnt = (curBCnt * 2) + curSCnt;
      curSCnt = curSCnt;
    } else {
      curSCnt = curSCnt * 2 + curBCnt;
      curBCnt = curBCnt;
    }
    SLen = SLen / 2;
    curLvl++;
  }
  if (SLen % 2 == 1)
    return curSCnt;
  else
    return curSCnt + curBCnt;
}
unsigned long long findSol(unsigned long long N, unsigned long long n) {
  unsigned long long level = findLevel(N, n);
  unsigned long long levelCnt = findLevelCnt(level, n);
  unsigned long long levelfBCnt = cntBOnLvl(N, false, 0, level);
  unsigned long long left = 0;
  unsigned long long right = N;
  if (cruelCase(N, n)) {
    long long lvl = 0;
    levelCnt = cruelLevelCnt(N, n);
    while (right - left > 3) {
      lvl++;
      unsigned long long leftLen = (right - left) / 2;
      unsigned long long rightLen = (right - left) - (right - left) / 2;
      unsigned long long leftCnt = cruelCnt(leftLen);
      unsigned long long rigthCnt = cruelCnt(rightLen);
      if (leftCnt < levelCnt) {
        levelCnt = levelCnt - leftCnt;
        left = left + (right - left) / 2;
      } else {
        levelCnt = levelCnt;
        right = left + (right - left) / 2;
      }
    }
    return left + levelCnt + 1;
  } else {
    if (levelfBCnt >= levelCnt) {
      unsigned long long curLvl = 0;
      unsigned long long curS = (right - left);
      while (curLvl < level) {
        curLvl++;
        curS = curS / 2;
        unsigned long long leftLen = (right - left) / 2;
        unsigned long long rightLen = (right - left) - (right - left) / 2;
        unsigned long long leftFB =
            cntBOnLvl(leftLen, leftLen != curS, curLvl, level);
        unsigned long long rightFB =
            cntBOnLvl(rightLen, rightLen != curS, curLvl, level);
        if (leftFB < levelCnt) {
          levelCnt = levelCnt - leftFB;
          left = left + (right - left) / 2;
        } else {
          levelCnt = levelCnt;
          right = left + (right - left) / 2;
        }
      }
    } else {
      levelCnt = levelCnt - levelfBCnt;
      unsigned long long curLvl = 0;
      unsigned long long curS = (right - left);
      while (curLvl < level) {
        curLvl++;
        curS = curS / 2;
        unsigned long long leftLen = (right - left) / 2;
        unsigned long long rightLen = (right - left) - (right - left) / 2;
        unsigned long long leftS =
            cntSOnLvl(leftLen, leftLen != curS, curLvl, level);
        unsigned long long rightS =
            cntSOnLvl(rightLen, rightLen != curS, curLvl, level);
        if (leftS < levelCnt) {
          levelCnt = levelCnt - leftS;
          left = left + (right - left) / 2;
        } else {
          levelCnt = levelCnt;
          right = left + (right - left) / 2;
        }
      }
    }
    return left + (right - left) / 2 + 1;
  }
}
int main() {
  unsigned long long N;
  unsigned long long n;
  cin >> N >> n;
  if (n == 1) {
    cout << 1;
    return 0;
  }
  if (n == 2) {
    cout << N;
    return 0;
  }
  n = n - 2;
  N = N - 1;
  cout << findSol(N, n) << endl;
  return 0;
}

```