#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const long long int ths = 1LL << 40;
const int NN = 5e3 + 6;
void solve() {
  long long int ans = 0;
  long long int n, x;
  cin >> n >> x;
  ans += x;
  ans += n - x;
  long long int t = min(x, n - x);
  if (t == x) {
    ans += t;
  }
  ans += t;
  ans += x + 1;
  cout << ans;
  cout << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
