#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Set(int N, int pos) { return (N | (1 << pos)); }
int fx[] = {-1, 0, 1, 0};
int fy[] = {0, 1, 0, -1};
inline long long BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
long long fac[2000005];
void FacGen() {
  fac[0] = 1;
  for (int i = 1; i <= 200000; i++) fac[i] = (fac[i - 1] * i) % MOD;
}
long long COM(long long a, long long b) {
  if (a < b) return 0;
  return ((fac[a] * BigMod((fac[b] * fac[a - b]) % MOD, MOD - 2, MOD)) % MOD +
          MOD) %
         MOD;
}
int ara[10];
int n, k;
int id, vis[10], cnt;
int dfs(int pos) {
  if (pos == 1) return 1;
  if (vis[pos] == id) return 0;
  vis[pos] = id;
  return dfs(ara[pos]);
}
void rec(int pos) {
  if (pos == k + 1) {
    int valid = 1;
    for (int i = 1; i <= k; i++) {
      id++;
      if (dfs(i) == 0) return;
    }
    cnt++;
    return;
  }
  for (int i = 1; i <= k; i++) {
    if (i != 1 and pos == i) continue;
    ara[pos] = i;
    rec(pos + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n >> k;
  rec(1);
  long long rem = n - k;
  long long pw = BigMod(rem, rem, MOD);
  cout << ((long long)pw * cnt) % MOD << "\n";
}
