#include <bits/stdc++.h>
using namespace std;
int a[101];
int main(void) {
  double n, x;
  cin >> n >> x;
  if (x == n / 2.0) {
    cout << (long long int)(3 * x);
  } else if (x < n / 2.0) {
    double ans = (((x * 2) / (n - 2 * x)) - 1) * (n - 2 * x) + 2 * x + n;
    cout << (long long int)ans;
  } else {
    double ans = ((x * 2) / (n - x)) * ((n - x)) + x;
    cout << (long long int)ans;
  }
  return 0;
}
