#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int N, K;
long long sol;
int A[10];
bool visit[10];
inline bool can(int i) {
  for (int c = 0; c < 10; c++) visit[c] = false;
  while (not visit[i]) {
    if (i == 1) return true;
    visit[i] = true;
    i = A[i];
  }
  return false;
}
inline void DFS(int i) {
  if (i == K + 1) {
    for (int c = 1; c <= K; c++)
      if (not can(c)) return;
    sol++;
    return;
  }
  for (int c = 1; c <= K; c++) {
    A[i] = c;
    DFS(i + 1);
  }
}
int main() {
  scanf("%d %d", &N, &K);
  DFS(1);
  for (int c = 0; c < N - K; c++) sol *= (N - K), sol %= MOD;
  printf("%I64d\n", sol);
}
