#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int perm[10];
int ans = 0;
int n, k;
void recur(int ind) {
  if (k == ind - 1) {
    for (int i = 1; i <= k; i++) {
      bool ok = false;
      int cur = i;
      for (int j = 1; j <= k && !ok; j++) {
        cur = perm[cur];
        if (cur == 1) ok = true;
      }
      if (!ok) return;
    }
    ans++;
    return;
  }
  for (int i = 1; i <= k; i++) {
    if (ind != 1 && i == ind) continue;
    perm[ind] = i;
    recur(ind + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  recur(1);
  long long int pw = n - k;
  for (int i = 1; i <= pw; i++) ans = (ans * 1LL * pw) % MOD;
  cout << ans << "\n";
  return 0;
}
