#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 31;
const long long INF = 1LL << 61;
const int MOD = 1000000007;
const int N = 123456;
const int M = 1010;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  long long n, x;
  cin >> n >> x;
  if (x + x > n) {
    x = n - x;
  }
  long long result = 3 * x + (n - x) + (n - 2 * x) * (x + 1);
  cout << result << '\n';
  return 0;
}
