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