#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  k = min(k, n - k + 1);
  cout << 3 * n + k - 1 << endl;
  return 0;
}
