#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, INF = 1e9;
using vi = vector<long long>;
using vvi = vector<vi>;
signed main() {
  long long n, x;
  cin >> n >> x;
  if (x > n - x) x = n - x;
  cout << n + n - x + n - x - x << endl;
}
