#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
using namespace std::rel_ops;
inline long long bit(int x) { return 1LL << x; }
template <class T>
inline bool chmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool chmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
  return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) is >> x;
  return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
  bool t = 0;
  for (const T& x : v.first) {
    if (t) os << v.second;
    os << x;
    t = 1;
  }
  return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
  return os << v * ' ';
}
struct before_main {
  before_main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
    ;
  };
} __before_main;
long long solve(long long n, long long k) {
  if (n == 1) return 0;
  long long a = n;
  long long ans = 0;
  while (k--) {
    a -= 2;
    if (a < 0) return ans;
    ans += 2 * a + 1;
  }
  return ans;
}
int main() {
  long long n, k;
  cin >> n >> k;
  cout << solve(n, k) << endl;
}
