#include <bits/stdc++.h>
using namespace std;
int main() {
  double n, x, ans, aans;
  cin >> n >> x;
  if (x == n / 2) {
    ans = x * 3;
  } else if (x < n / 2) {
    ans = x + (n - x) + x + x + (n - x - x) * 3;
  } else if (x > n / 2) {
    ans = x + ((n / (n - x)) * 2 - 2) * (n - x);
  }
  cout << ans << endl;
  return 0;
}
