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