#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, k;
int p[9], vis[9], visID;
bool check() {
  for (int i = 1; i <= k; ++i) {
    ++visID;
    int cur = p[i];
    while (cur != 1) {
      if (vis[cur] == visID) return false;
      vis[cur] = visID;
      cur = p[cur];
    }
  }
  return true;
}
int go(int i) {
  if (i == k + 1) return check();
  int ret = 0;
  for (int j = 1; j <= k; ++j) {
    if (j != 1 && j == i || j < i && p[j] == i && j != 1) continue;
    p[i] = j;
    ret = (ret + go(i + 1)) % MOD;
  }
  return ret;
}
long long power(int base, int exp) {
  long long ret = 1;
  while (exp) {
    while (exp % 2 == 0) {
      base = (1LL * base * base) % MOD;
      exp /= 2;
    }
    ret = (ret * base) % MOD;
    --exp;
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &k);
  printf("%lld\n", (go(1) * power(n - k, n - k)) % MOD);
  return 0;
}
