#include <bits/stdc++.h>
using namespace std;
int n, k;
int sol;
int cnt[5010];
bool gotov[5010];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cnt[i] = 1;
  if (n - k + 1 < k) k = n - k + 1;
  if (k <= n - k + 1) {
    int sada = k;
    if (sada > 1) {
      sol++;
      sol++;
      sol++;
      cnt[sada] = 0;
      gotov[sada] = true;
      sada--;
      cnt[sada]++;
    }
    while (sada > 0) {
      sol += cnt[sada];
      cnt[sada + 1] += cnt[sada];
      cnt[sada] = 0;
      sol++;
      gotov[sada] = true;
      if (sada > 1) sol++;
      sada--;
    }
    sada = 1;
    while (sada <= n) {
      if (gotov[sada]) {
        sada++;
        sol++;
        continue;
      }
      gotov[sada] = true;
      if (sada >= 1) {
        cnt[sada - 1] += cnt[sada];
        sol += cnt[sada];
        cnt[sada] = 0;
        sol++;
      } else {
        cnt[sada + 1] += cnt[sada];
        sol += cnt[sada];
        cnt[sada] = 0;
        sol++;
      }
      if (sada < n) {
        sol++;
        sada++;
      } else
        break;
    }
  }
  cout << sol << endl;
  return 0;
}
