#include <bits/stdc++.h>
using namespace std;
long long d[10], dp[1111][11], n, k;
long long c(long long x, long long y) {
  long long p = 1, q = 1, z;
  for (long long i = 0; i < y; i++) {
    p *= (x - i);
    q *= (1 + i);
  }
  p /= q;
  return p;
}
int main() {
  cin >> n >> k;
  d[0] = 1;
  for (long long i = 2; i <= 4; i++) d[i] = (i - 1) * (d[i - 1] + d[i - 2]);
  for (long long i = 1; i <= 1000; i++) dp[i][0] = 1;
  for (long long i = 1; i <= 1000; i++) {
    for (long long j = 1; j <= min((long long)4, i); j++) {
      dp[i][j] = dp[i][j - 1] + c(i, j) * d[j];
    }
  }
  cout << dp[n][k];
}
