#include <bits/stdc++.h>
using namespace std;
void println(vector<int> x) {
  for (int i = 0; i < (int)x.size(); i++)
    printf("%d%c", x[i], " \n"[i == (int)x.size() - 1]);
}
void println(vector<long long> x) {
  for (int i = 0; i < (int)x.size(); i++)
    printf("%lld%c", x[i], " \n"[i == (int)x.size() - 1]);
}
void scanln(vector<int>& x, int sz) {
  x.resize(sz);
  for (int i = 0; i < sz; i++) scanf("%d", &x[i]);
}
void scanln(vector<long long>& x, int sz) {
  x.resize(sz);
  for (int i = 0; i < sz; i++) scanf("%lld", &x[i]);
}
template <class T>
void read(T* x, int l, int r) {
  for (int i = l; i <= r; i++) read(x[i]);
}
void println(int* x, int l, int r) {
  for (int i = l; i <= r; i++) printf("%d%c", x[i], " \n"[i == r]);
}
void println(long long* x, int l, int r) {
  for (int i = l; i <= r; i++) printf("%lld%c", x[i], " \n"[i == r]);
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  scanf("%d%d", &n, &k);
  cout << 3 * n + min(k - 1, n - k) << endl;
  return 0;
}
