#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, mod9 = 1000000009;
template <class T>
inline T lcm(T a, T b) {
  return (a * b / __gcd(a, b));
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, x;
  cin >> n >> x;
  if (x * 2 == n) {
    cout << x * 3 << endl;
  } else {
    cout << (min(x * 6, (n - x) * 6)) << endl;
  }
  return 0;
}
