#include <bits/stdc++.h>
using namespace std;
long long n, x, mid;
int main() {
  scanf("%lld%lld", &n, &x);
  if (n % 2 == 0) {
    mid = n / 2;
    if (mid == x) {
      printf("%lld", 2 * n - x);
      return 0;
    }
  }
  printf("%lld", min(n - x, x) + 2 * n);
  return 0;
}
