#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 5;
int main(void) {
  int n, k;
  scanf("%d%d", &n, &k);
  printf("%d\n", n + n + 1 + n - 1 + min(abs(1 - k), abs(n - k)));
  return 0;
}
