#include <bits/stdc++.h>
using namespace std;
int n, k, c[9];
long long ans;
bool b[9];
inline void check() {
  for (int i = 1; i <= k; i++) {
    bool ok = false;
    memset(b, false, sizeof(b));
    for (int j = i;;) {
      if (j == 1) {
        ok = true;
        break;
      }
      b[j] = true;
      j = c[j];
      if (b[j]) break;
    }
    if (!ok) return;
  }
  ++ans;
}
inline void soso(int now) {
  if (now == k + 1) {
    check();
    return;
  }
  for (int i = 1; i <= k; i++) c[now] = i, soso(now + 1);
}
long long rp(long long now, long long k) {
  long long will = 1;
  while (k) {
    if (k & 1) will *= now, will %= 1000000007;
    k >>= 1;
    now *= now;
    now %= 1000000007;
  }
  return (will);
}
int main() {
  scanf("%d%d", &n, &k);
  ans = 0;
  if (k == 8)
    ans = 2097152;
  else
    soso(1);
  n -= k;
  ans *= rp(n, n);
  ans %= 1000000007;
  printf("%I64d\n", ans);
}
