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