#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
const int mod = 1000000009;
int n;
int ar[MAXN];
int main() {
  long long n, x;
  cin >> n >> x;
  cout << x + (n - x) + x + x + (n - x - x) * 3 << "\n";
}
