#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k = 0, i, t = 0, j, m, b, x = 0, y = 0;
  cin >> n >> j;
  k += 3 * j;
  k += n - j;
  k += 3 * (n - 2 * j);
  cout << k;
  return 0;
}
