#include <bits/stdc++.h>
using namespace std;
void R() {}
const int maxn = 134;
int main() {
  int n, k;
  cin >> n >> k;
  int m = 3 * n;
  int p = (n + 1) / 2;
  if (n % 2) {
    if (k <= p)
      m += k - 1;
    else {
      m += n - k;
    }
  } else {
    if (k <= p)
      m += k - 1;
    else {
      m += n - k;
    }
  }
  cout << m << endl;
}
