#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int MOD = 1000000007;
const int MAX = 100000;
const int INF = 100000000;
vector<int> a;
int n, k;
bool ok = 1;
void add() {
  int i = 0;
  while (i < a.size() && a[i] == k - 1) ++i;
  if (i == a.size())
    ok = 0;
  else {
    a[i]++;
    for (int j = (0); j < (i); ++j) a[j] = 0;
  }
}
int b[10];
int f(int v) {
  if (b[v] != -1) return b[v];
  if (a[v - 1] == v) return b[v] = 0;
  b[v] = 0;
  return b[v] = f(a[v - 1]);
}
int main() {
  cin >> n >> k;
  a.resize(k - 1, 0);
  int cnt = 0;
  while (ok) {
    memset(b, -1, sizeof(b));
    b[0] = 1;
    for (int i = (0); i < (k - 1); ++i) f(i + 1);
    bool q = 1;
    for (int i = (1); i < (k); ++i)
      if (!b[i]) q = 0;
    cnt += q;
    add();
  }
  long long res = 1;
  for (int i = (0); i < (n - k); ++i) res = res * (n - k) % MOD;
  res = (res * (k)) % MOD;
  res = (res * cnt) % MOD;
  cout << res << endl;
  return 0;
}
