#include <bits/stdc++.h>
long N;
long X;
int main() {
  long i, j;
  long ans = 0;
  scanf("%ld %ld", &N, &X);
  if (N % 2) {
    ans = (N - 1) * 3;
  } else {
    if (N / 2 == X) {
      ans = N / 2 * 3;
    } else if (X % 2) {
      ans = (N / 2 - 1) * 6;
    } else {
      ans = (N - 1) * 3;
    }
  }
  printf("%ld\n", ans);
  return 0;
}
