#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int n, k;
long long int ans = 0;
const long long int mod = 1000000007;
int mig[10];
int state[10], vis[10];
bool rec(int v) {
  if (state[v] == 1) return true;
  if (vis[v]) return false;
  vis[v] = 1;
  if (!rec(mig[v])) return false;
  state[v] = 1;
  return true;
}
bool judge() {
  for (int i = 0; i < k; ++i) state[i] = -1, vis[i] = 0;
  state[0] = 1;
  for (int i = 0; i < k; ++i)
    if (state[i] == -1) {
      if (rec(i) == 0) return false;
    }
  return true;
}
void dfs(int dep) {
  if (dep == k) {
    if (judge()) ++ans;
    return;
  }
  for (int i = 0; i < k; ++i) {
    mig[dep] = i;
    dfs(dep + 1);
  }
}
int main() {
  cin >> n >> k;
  dfs(1);
  ans = (ans * k) % mod;
  for (int i = k; i < n; ++i) ans = (ans * (n - k)) % mod;
  cout << ans << endl;
  return 0;
}
