#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  int a, b, c;
  a = k;
  b = n - k;
  c = abs(a - b);
  int ans = 3 * a + b + 3 * c;
  cout << ans;
  return 0;
}
