#include<bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int moves = 0, throws = 0, picks = 0;
if (k <= (n / 2)) {
moves += (k - 1);
} else {
moves += (n - k);
}
moves += (n - 1);
picks += n;
throws += (n + 1);
cout << (moves + throws + picks);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJaW50IG4sIGs7CgljaW4gPj4gbiA+PiBrOwoJCglpbnQgbW92ZXMgPSAwLCB0aHJvd3MgPSAwLCBwaWNrcyA9IDA7CgkKCWlmIChrIDw9IChuIC8gMikpIHsKCQltb3ZlcyArPSAoayAtIDEpOwoJfSBlbHNlIHsKCQltb3ZlcyArPSAobiAtIGspOwoJfQoJCgltb3ZlcyArPSAobiAtIDEpOwoJcGlja3MgKz0gbjsKCXRocm93cyArPSAobiArIDEpOwoKCWNvdXQgPDwgKG1vdmVzICsgdGhyb3dzICsgcGlja3MpOwogICAgCiAgICByZXR1cm4gMDsKfQo=