#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
long long kol, n, k, a[100][100], pos[100], posk = 0, t = 0;
int dfs(int h);
int q(int i) {
  if (i < k) {
    for (int j = 0; j < k; j++) {
      a[j][i] = 1;
      q(i + 1);
      a[j][i] = 0;
    }
  } else
    t += dfs(0);
  return 0;
}
int dfs(int h) {
  int o = 0;
  if (h == 0) {
    posk = 1;
    for (int i = 0; i < k; i++) {
      pos[i] = 0;
    }
  }
  for (int i = 0; i < k; i++) {
    if (a[h][i] == 1 && pos[i] == 0) {
      pos[i] = 1;
      posk++;
      if (posk == k)
        return 1;
      else
        o = dfs(i);
      if (o == 1) return 1;
    }
  }
  if (posk == k) return 1;
  return 0;
}
int main() {
  long long res = 1;
  cin >> n >> k;
  q(1);
  res = t % 1000000007;
  res *= k % 1000000007;
  for (int i = 0; i < n - k; i++) {
    res *= (n - k);
    res = res % 1000000007;
  }
  cout << res;
  cin >> kol;
}
