#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000 * 1000 * 1000 + 7LL;
const double EXP = 1e-6;
const int MAX = 100001;
int mark[9];
long long n, k;
bool vis[9];
bool all[9];
int dfs(int u) {
  if (u == 1) return 1;
  if (vis[u] == 1) return 0;
  vis[u] = 1;
  return dfs(mark[u]);
}
long long f(int u) {
  if (k == 1) return 1;
  if (k == 2) return 2;
  if (k == 3) return 9;
  if (k == 4) return 64;
  if (k == 5) return 625;
  if (k == 6) return 7776;
  if (k == 7) return 117649;
  if (k == 8) return 2097152;
  if (u == k + 1) {
    long long b = 1LL;
    for (int i = 1; i <= k; i++) {
      memset(vis, 0, sizeof vis);
      if (!dfs(i)) b = 0;
    }
    return b;
  }
  long long ans = 0LL;
  for (int i = 1; i <= k; i++) {
    mark[u] = i;
    ans = (ans + f(u + 1)) % mod;
  }
  return ans % mod;
}
int main() {
  cin >> n >> k;
  long long ans = 1;
  for (int i = k + 1; i <= n; i++) {
    ans = (ans * (n - k)) % mod;
  }
  ans = (ans * f(1)) % mod;
  cout << ans << endl;
  return 0;
}
