#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 2 * 1000 * 1000 * 1000;
int k, cur, f[20], n, kk, a[20], ans = 1ll, sum;
void calc() {
  kk = 1, cur = f[k - 1];
  for (int i = 2; i < k; i++)
    if (a[i] == a[i - 1])
      kk++;
    else
      cur /= f[kk], kk = 1;
  cur /= f[kk];
  sum = (sum + 0ll + cur) % mod;
}
void rec(int v, int c) {
  if (v >= k) {
    calc();
    return;
  }
  for (int i = c; i <= v; i++) {
    a[v] = i;
    rec(v + 1, i);
  }
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n - k; i++) ans = (ans * 1ll * (n - k)) % mod;
  f[0] = 1ll;
  for (int i = 1; i <= 10; i++) f[i] = f[i - 1] * i;
  ans = (ans * 1ll * k) % mod;
  rec(1, 1);
  ans = (ans * 1ll * sum) % mod;
  cout << ans;
  return 0;
}
