#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n, first;
  cin >> n >> first;
  unsigned long long ans = 0LL;
  if (2 * first < n) {
    ans += first + (n - first) + first + first;
    unsigned long long ans1;
    ans1 = (n - 2 * first) * (2 * first - 1);
    cout << ans1 + ans << "\n";
  } else if (2 * first == n) {
    ans += first + (n - first) + first;
    cout << ans << "\n";
  } else {
    ans += first + (n - first) + first + (n - first) + first + (n - first);
    cout << ans << "\n";
  }
  return 0;
}
