#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  long long N, X;
  cin >> N >> X;
  long long ans, a = N - X;
  ans = X + a + (N - a) * 2 + (a - (N - a)) * 3;
  cout << ans << endl;
  return 0;
}
