#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
long long solve() {
  long long ret = 0;
  long long N, X;
  cin >> N >> X;
  ret += X + (N - X) + (N - (N - X)) * 2 + ((N - X) - (N - (N - X))) * 3;
  return ret;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << solve() << endl;
  return 0;
}
