#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int N, K;
int to[10];
int ok[10];
bool chk_dfs(int v) {
  ok[v] = 0;
  bool res = false;
  if (to[v] == 1) {
    ok[v] = 1;
    return true;
  }
  if (ok[to[v]] == -1) {
    res = chk_dfs(to[v]);
    ok[v] = (res ? 1 : 0);
  } else if (ok[to[v]] == 0) {
    res = false;
    ok[v] = 0;
  } else {
    res = true;
    ok[v] = 1;
  }
  return res;
}
bool chk() {
  memset(ok, -1, sizeof(ok));
  for (int i = 2; i <= K; i++) {
    if (ok[i] != -1) continue;
    if (!chk_dfs(i)) return false;
  }
  return true;
}
int dfs(int v) {
  if (v > K) {
    return chk() ? 1 : 0;
  }
  int res = 0;
  for (int i = 1; i <= K; i++) {
    if (i == v) continue;
    to[v] = i;
    res += dfs(v + 1);
    res %= MOD;
  }
  return res;
}
int main() {
  istream& in = cin;
  in >> N >> K;
  long long ans = K;
  if (K > 1) {
    ans *= dfs(2);
    ans %= MOD;
  }
  if (N != K) {
    for (int i = K + 1; i <= N; i++) {
      ans *= (N - K);
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
