#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long ans = 1;
  for (int i = k + 1; i <= n; i++) ans = (ans * (n - k)) % 1000000007;
  ans = (ans * (k)) % 1000000007;
  if (k - 1 > 0) {
    long long prod = 0;
    vector<int> v(k + 2);
    int loopval = 1;
    for (int i = 1; i <= k - 1; i++) loopval *= k;
    for (int i = 0; i < loopval; i++) {
      int temp = i;
      for (int j = 0; j < k - 1; j++) {
        v[j + 2] = temp % k + 1;
        temp /= k;
      }
      int j = 0;
      for (; j < k - 1; j++) {
        int steps = 0;
        temp = v[j + 2];
        while (steps <= 7 && temp > 1) {
          temp = v[temp];
          steps++;
        }
        if (temp > 1) break;
      }
      if (j == k - 1) prod++;
    }
    ans = (ans * (prod)) % 1000000007;
  }
  cout << ans << endl;
}
