#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
long long n, k, ans, res;
int a[10], vis[10];
long long dfs(int cur) {
  if (cur > k) {
    bool f = 1;
    for (int i = 2; i <= k; i++) {
      memset(vis, 0, sizeof(vis));
      vis[i] = 1;
      int u = a[i];
      while (u != 1) {
        if (vis[a[u]]) break;
        vis[a[u]] = 1;
        u = a[u];
      }
      if (u != 1) {
        f = 0;
        break;
      }
    }
    if (f) {
      res++;
      res %= mod;
    }
    return res;
  }
  for (int i = 1; i <= k; i++) {
    a[cur] = i;
    dfs(cur + 1);
  }
  return res;
}
int main() {
  cin >> n >> k;
  ans = 1;
  for (int i = 1; i <= (n - k); i++) {
    ans = (ans * (n - k)) % mod;
  }
  ans = (ans * k) % mod;
  ans = (ans * dfs(2)) % mod;
  cout << ans << endl;
  return 0;
}
