#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const long long int MOD = 1e9 + 7;
long long int N, K, res = 1LL, res2 = 0LL;
int ar[MAXN];
string s;
void dfs(int pl) {
  if (pl == K) {
    for (int i = 1; i <= K; i++) {
      int c = 0;
      bool fl = 0;
      for (int j = i; c < K + 5; j = ar[j], c++)
        if (ar[j] == 1) {
          fl = 1;
          break;
        }
      if (fl == 0) return;
    }
    res2++;
    return;
  }
  for (int i = 1; i <= K; i++) {
    ar[pl + 1] = i;
    dfs(pl + 1);
  }
}
int main() {
  cin >> N >> K;
  for (int i = 1; i <= N - K; i++) res = (res * (N - K)) % MOD;
  for (int i = 1; i <= K; i++) {
    ar[1] = i;
    dfs(1);
  }
  cout << (res * res2) % MOD << endl;
  return 0;
}
