#include <bits/stdc++.h>
using namespace std;
int n, k, p[10], t[10];
long long ans;
void rec(int sz) {
  if (sz == k - 1) {
    for (int j = 0; j < k; j++) {
      memset(t, -1, sizeof(t));
      int v = j;
      while (t[v] == -1) {
        t[v] = 1;
        v = p[v];
      }
      if (!t[0]) return;
    }
    ans++;
  } else {
    for (int j = 0; j < k; j++) {
      p[sz] = j;
      rec(sz + 1);
    }
  }
}
int main() {
  while (cin >> n >> k) {
    ans = 0;
    rec(0);
    for (int i = 0; i < n - k; i++) ans = (ans * (n - k)) % 1000000007;
    cout << ans << endl;
  }
  return 0;
}
