#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) {
  while (a) swap(a, b %= a);
  return b;
}
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
  ll N, X;
  cin >> N >> X;
  cout << 3 * max(X, N - X) << endl;
}
