#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int mul(int a, int b) { return (long long int)a * b % M; }
int power(int a, int b) {
  if (b == 0) return 1;
  int temp = power(a, b / 2);
  if (b % 2 == 0)
    return mul(temp, temp);
  else
    return mul(a, mul(temp, temp));
}
int inv(int v) { return power(v, M - 2); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  int mid = (n + 1) / 2;
  long long int sum = 0;
  if (k <= mid) {
    if (k != 1) {
      sum += 6;
      sum += 3 * (k - 2);
      sum += (k - 1);
      sum += 3 * (n - k);
    } else {
      sum += 6;
      sum += 3 * (n - 2);
    }
  } else {
    if (k != n) {
      sum += 6;
      sum += 3 * (n - (k + 2));
      sum += (n - k);
      sum += 3 * k;
    } else {
      sum += 6;
      sum += 3 * (n - 2);
    }
  }
  cout << sum << endl;
}
