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