#include <bits/stdc++.h>
using namespace std;
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cerr << b << " = " << a << " ";
    call(++it, ed, rest...);
  }
};
int main() {
  int n, k;
  while (cin >> n >> k) {
    int s;
    if (k == 1 || n == k) {
      s = 3 * n;
    } else {
      s = 3 * n + min(n - k, k - 1);
    }
    cout << s << endl;
  }
}
