#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = MOD + 1;
const long double EPS = 1e-12;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
int main() {
  cin.sync_with_stdio(false);
  long long n, x;
  cin >> n >> x;
  if (n % 2) {
    cout << n / 2 * 6 << endl;
  } else {
    if (x > n / 2) x = n - x;
    cout << (n - x) * 3 << endl;
  }
  return 0;
}
