#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, i, j, ans = 0;
  cin >> n >> x;
  if (n % 2 == 0 && n / 2 == x) {
    cout << x + n;
  } else if (x <= n / 2) {
    cout << x + (n - x) + 2 * x + 3 * (n - 2 * x);
  } else {
    cout << x + 4 * (n - x);
  }
  return 0;
}
