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