#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e15;
const long long int MOD = 1e9 + 7;
template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()) {
  return vector2<T>(n0, vector<T>(n1, e));
}
template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()) {
  return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, k;
  cin >> n >> k;
  long long int ans = 2 * n + 1 + min(n + k - 2, 2 * n - k - 1);
  cout << ans << endl;
  return 0;
}
