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