#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int K_MAX = 8;
int n, k;
long long dp[K_MAX];
void solve() {
  dp[0] = 1;
  dp[1] = 1;
  for (int i = 2; i < k; ++i) {
    dp[i] = 1;
    for (int j = 0; j < (i); ++j) dp[i] = (dp[i] * (i + 1)) % M;
    for (int j = 1; j <= i; ++j) {
      long long x = 1;
      for (int k = 0; k < (j); ++k) x = x * (i - k) / (k + 1);
      for (int k = 0; k < (j); ++k) x = (x * j) % M;
      x = (x * dp[i - j]) % M;
      dp[i] = (dp[i] - x) % M;
    }
  }
  long long ans = k;
  for (int i = 0; i < (n - k); ++i) ans = (ans * (n - k)) % M;
  ans = (ans * dp[k - 1]) % M;
  cout << ans << endl;
}
int main() {
  cin >> n >> k;
  solve();
  return 0;
}
