#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[9];
long long Count = 0;
void recurs(int cnt) {
  if (cnt == 0) {
    for (int i = 1; i <= k; i++) {
      int cur = i;
      for (int j = 1; j < k && cur != 1; j++) {
        cur = a[cur];
      }
      if (cur != 1) return;
    }
    Count++;
    Count %= (long long)1000000007;
    return;
  }
  for (int i = 1; i <= k; i++) {
    a[cnt] = i;
    recurs(cnt - 1);
  }
}
int main() {
  cin >> n >> k;
  int temp = n - k;
  long long tt = 1;
  for (int i = 0; i < temp; i++) {
    tt *= temp;
    tt %= (long long)1000000007;
  }
  if (k < 8)
    recurs(k);
  else
    Count = 2097152;
  long long ans = tt * Count;
  ans %= (long long)1000000007;
  cout << ans << endl;
  return 0;
}
