#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n >> x;
  long long ans;
  if (x * 2 == n) {
    ans = x + (n - x) + x;
  } else {
    ans = x + (n - x) + x + (n - x) + x;
  }
  cout << ans << endl;
}
