#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
void shit() { puts("NO"); }
void good() { puts("YES"); }
inline int rd() {
  int ret = 0, f = 1;
  char c;
  while (c = getchar(), !isdigit(c)) f = c == '-' ? -1 : 1;
  while (isdigit(c)) ret = ret * 10 + c - '0', c = getchar();
  return ret * f;
}
void pot(int x) {
  if (!x) return;
  pot(x / 10);
  putchar('0' + x % 10);
}
void out(int x) {
  if (!x) putchar('0');
  if (x < 0) putchar('-'), x = -x;
  pot(x);
}
void solve() {
  int n = rd();
  int k = rd();
  out(min(n - k, k - 1) + 3 + (2 * (n - 1)) + n - 1);
}
int main() {
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
