#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, X;
  scanf("%lld %lld\n", &N, &X);
  long long result = 0;
  if (N % 2 == 0) {
    if (X == N / 2) {
      printf("%lld\n", X * 3);
      return 0;
    } else if (X % 2 == 0) {
      result += (X + (N - X) + X);
      long long left = N - 2 * X;
      result += left * 2;
      printf("%lld", result);
      return 0;
    }
  }
  result += (X + (N - X) + X);
  result += X;
  return 0;
}
