#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, sum;
  cin >> a >> b;
  if (a - b == b) {
    sum = 3 * b;
  } else if (a - b < b) {
    sum = (b / 2) * 3;
  } else {
    sum = 3 * b + 2 * (a - b);
  }
  cout << sum;
}
