#include <bits/stdc++.h>
using namespace std;
int N, K, C[20], F[20], can[20];
long long ret, fac;
void DFS(int a) {
  if (a > K) {
    memset(can, 0, sizeof(can));
    for (int i = 2; i <= K; i++) {
      int p = i;
      memset(F, 0, sizeof(F));
      while (1) {
        if (can[p] || p == 1) {
          can[i] = 1;
          break;
        }
        if (F[p]) break;
        F[p] = 1;
        p = C[p];
      }
      if (!can[i]) return;
    }
    if (!can[C[1]] && C[1] != 1) return;
    ret = (ret + fac) % 1000000007LL;
    return;
  }
  for (int i = 1; i <= K; i++) C[a] = i, DFS(a + 1);
}
int main() {
  scanf("%d%d", &N, &K);
  fac = 1LL;
  for (int i = 1; i <= N - K; i++)
    fac = (fac * (long long)(N - K)) % 1000000007LL;
  DFS(1);
  printf("%lld\n", ret);
  return 0;
}
