#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long dp[9][1 << 8];
int a[9];
int f[9];
bool v[9];
int k, n;
long long ans = 0;
bool dfs1(int ps) {
  if (f[ps] != -1) return f[ps];
  v[ps] = 1;
  if (a[ps] == 1)
    f[ps] = 1;
  else if (v[a[ps]] && f[a[ps]] == -1)
    f[ps] = 0;
  else
    f[ps] = dfs1(a[ps]);
  return f[ps];
}
void dfs(int ps) {
  if (ps == k + 1) {
    memset(f, -1, k + 1 << 2);
    memset(v, 0, k + 1);
    bool ok = 1;
    for (int j = 2; j <= k; j++) {
      if (!v[j] && !dfs1(j)) {
        ok = 0;
        break;
      }
    }
    if (ok) ans++;
    return;
  }
  for (int i = 1; i <= k; i++) {
    a[ps] = i;
    dfs(ps + 1);
  }
}
int main() {
  scanf("%d %d", &n, &k);
  dfs(2);
  ans = ans * k % MOD;
  for (int i = k + 1; i <= n; i++) ans = ans * (n - k) % MOD;
  printf("%d\n", ans);
}
