#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n, k, ans = 0;
int powmod(int b, int e) {
  if (!e) return 1;
  if (e & 1) return (1LL * b * powmod(b, e - 1)) % MOD;
  int aux = powmod(b, e >> 1);
  return (1LL * aux * aux) % MOD;
}
bool flg[10];
int vec[10], memo[10];
bool ok(int x) {
  if (vec[x] == 1) return true;
  if (memo[x] != -1) return memo[x];
  if (flg[x]) return memo[x] = false;
  flg[x] = true;
  return memo[x] = ok(vec[x]);
}
void solve(int pos) {
  if (pos == k + 1) {
    memset(flg, false, sizeof flg);
    memset(memo, -1, sizeof memo);
    for (int i = 1; i <= k; ++i)
      if (!ok(i)) return;
    return void(ans++);
  }
  for (int i = 1; i <= k; ++i) {
    vec[pos] = i;
    solve(pos + 1);
  }
}
int main() {
  scanf("%d %d", &n, &k);
  solve(1);
  printf("%d\n", (1LL * ans * powmod(n - k, n - k)) % MOD);
}
