#include <bits/stdc++.h>
using namespace std;
int K, N;
const int MAXN = 1010;
list<int> G[MAXN];
int used[10];
int t;
int ar[10];
int kont() {
  memset(used, 0, sizeof(used));
  for (int(i) = (K); (i) >= (2); (i)--)
    if (!used[i]) {
      t = i;
      while (t != 1 && t && !used[t]) {
        used[t] = 1;
        t = ar[t];
      }
      if (t != 1 && used[t] != 2) {
        return 0;
      }
      t = i;
      while (t != 1 && t && used[t] != 2) {
        used[t] = 2;
        t = ar[t];
      }
    }
  return 1;
}
int beg;
const int MOD = 1e9 + 7;
void f(int k) {
  if (k == K + 1) {
    beg = (beg + kont()) % MOD;
    return;
  }
  for (int(i) = (1); (i) <= (K); (i)++)
    if (i != k) {
      ar[k] = i;
      f(k + 1);
    }
}
int main() {
  scanf("%d %d", &N, &K);
  f(2);
  long long X = N - K;
  long long res = (beg * (K)) % MOD;
  for (int(i) = (1); (i) <= (X); (i)++) res = (res * X) % MOD;
  cout << res << endl;
  return 0;
}
