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