#include <bits/stdc++.h>
using namespace std;
void gen(int *, int, int, long long &);
int main() {
  int n, k, to[10];
  long long m = 0;
  cin >> n >> k;
  gen(to, 1, k, m);
  m = (m * k) % 1000000007;
  for (int i = k + 1; i <= n; i++) m = (m * (n - k)) % 1000000007;
  cout << m << endl;
  return 0;
}
void gen(int *to, int step, int end, long long &m) {
  if (step == end) {
    int flag = 1;
    for (int i = 1; flag && i < end; i++)
      for (int cnt = 0, k = to[i]; flag && k; k = to[k], cnt++)
        if (cnt > end) flag = 0;
    m += flag;
    return;
  }
  for (int i = 0; i < end; i++) {
    to[step] = i;
    gen(to, step + 1, end, m);
  }
}
