#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long N, X;
  cin >> N >> X;
  if (N % 2 == 0 && X % 2 == 0) {
    cout << 3 * (N - 2) << endl;
  } else {
    cout << 3 * (N - 1) << endl;
  }
  return 0;
}
