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