#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a, b;
  cin >> a >> b;
  if (b == 1 || b == a) {
    cout << a * 3 << '\n';
  } else
    cout << a * 3 + min(b - 1, a - b) << '\n';
}
