#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, ans = 0, e[3], idx = 0;
  cin >> n >> x;
  fill(e, e + 3, n);
  e[idx] -= x;
  while (e[0]) {
    ans += x;
    ++idx;
    idx = idx % 3;
    x = e[idx] - x;
    e[idx] -= x;
  }
  cout << ans << endl;
  return 0;
}
