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