#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 405;
const long long mod = 1000000007;
const double PI = acos(-1.0);
long long n, x;
void solve() {
  cin >> n >> x;
  if (x * 2 >= n) {
    printf("%lld\n", 3 * x);
  } else if (x * 3 <= n) {
    printf("%lld\n", 3 * (n - x));
  } else {
    printf("%lld\n", 6 * x);
  }
}
int main() {
  solve();
  return 0;
}
