#include <bits/stdc++.h>
using namespace std;
const long long p = 1000000007;
long long t[1010][10];
long long n, k;
long long add(long long a, long long b) { return (a + b) % p; }
long long mul(long long a, long long b) { return (a * b) % p; }
long long fac(long long a) {
  long long r = 1;
  for (long long i = 1; i <= a; i++) r = mul(r, i);
  return r;
}
long long exp(long long a, long long n) {
  if (n == -1) {
    assert(a == 1);
    return 1;
  }
  long long r = 1;
  for (int i = 0; i < int(n); ++i) r = mul(r, a);
  return r;
}
long long choose(long long n, long long k) {
  if (n < k) return 0;
  if (0) printf("%I64d %I64d %I64d\n", n, k, t[n][k]);
  return t[n][k];
}
long long numTrees(long long n) { return exp(n, n - 2); }
int main() {
  scanf("%I64d %I64d", &n, &k);
  for (int i = 0; i <= n; i++) {
    t[i][0] = 1;
    for (int j = 1; j <= k; j++)
      t[i][j] = add(t[i - 1][j - 1], (j <= i - 1) ? t[i - 1][j] : 0);
  }
  long long r = 0;
  for (int s = 0; s <= k - 1; s++) {
    long long cycleChoices = choose(k - 1, s);
    long long tmp[10];
    long long todo = k - 1 - s;
    tmp[0] = 1;
    for (int i = 1; i <= todo; i++) {
      tmp[i] = 0;
      for (int j = 0; j <= i - 1; j++) {
        long long setChoices = choose(i - 1, j);
        long long prev = tmp[i - j - 1];
        long long trees = numTrees(j + 1);
        trees = mul(trees, s + 1);
        trees = mul(trees, j + 1);
        tmp[i] = add(tmp[i], mul(mul(setChoices, prev), trees));
      }
      if (0) printf("tmp[%d]=%I64d\n", i, tmp[i]);
    }
    long long treeBuilds = tmp[todo];
    cycleChoices = mul(cycleChoices, fac(s));
    if (0)
      printf("s %d cycleChoices %I64d treeBuilds %I64d\n", s, cycleChoices,
             treeBuilds);
    r = add(r, mul(cycleChoices, treeBuilds));
  }
  if (0) printf("step %I64d\n", r);
  r = mul(r, exp(n - k, n - k));
  printf("%I64d\n", r);
  return 0;
}
