#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  if (k > n / 2)
    cout << 4 * n - k << endl;
  else
    cout << 3 * n + k - 1 << endl;
  return 0;
}
