#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int N, K, Ans, P[10], Used[10], Cnt = 0;
vector<int> G[10];
void DFS(int Node) {
  Cnt++;
  Used[Node] = 1;
  for (int i = 0; i < G[Node].size(); ++i)
    if (!Used[G[Node][i]]) DFS(G[Node][i]);
  Used[Node] = 0;
}
void Back(int Pos) {
  if (Pos > K) {
    Cnt = 0;
    DFS(1);
    if (Cnt == K) Ans++;
    return;
  }
  for (int i = 1; i <= K; ++i) {
    G[i].push_back(Pos);
    Back(Pos + 1);
    G[i].pop_back();
  }
}
int main() {
  scanf("%i %i", &N, &K);
  Back(1);
  for (int i = 1; i <= N - K; ++i) Ans = (1LL * Ans * (N - K)) % MOD;
  printf("%i", Ans);
}
