#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long n, x;
  cin >> n >> x;
  if (x * 2 < n) {
    cout << x + n - x + x + x + 2 * x - (n - x * 2) << endl;
  } else if (x * 2 == n) {
    cout << 3 * x << endl;
  } else {
    cout << 3 * x << endl;
  }
}
