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