#include <bits/stdc++.h>
using namespace std;
void DBG() { cerr << "]\n"; }
template <typename T, typename... Args>
void DBG(T first, Args... args) {
  cerr << first;
  if (sizeof...(args)) cerr << ", ";
  DBG(args...);
}
long long ncr(long long n, long long k) {
  k = n - k;
  long long fact = 1;
  long long num = 1;
  for (long long i = 1; i <= k; i++) {
    fact *= i;
    num *= (n - i + 1);
  }
  return num / fact;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> derrangement(n + 1);
  derrangement[0] = 1;
  derrangement[1] = 0;
  derrangement[2] = 1;
  for (long long i = 3; i <= k; i++) {
    derrangement[i] = (i - 1) * (derrangement[i - 1] + derrangement[i - 2]);
  }
  long long ans = 0;
  for (long long i = n - k; i <= n; i++) {
    ans += ncr(n, i) * derrangement[n - i];
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  for (long long tt = 1; tt <= t; tt++) {
    solve();
  }
}
