#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10;
const int MAXE = 10;
const int mod = 1e9 + 7;
struct Edge {
  int v, n;
  Edge() {}
  Edge(int v, int n) : v(v), n(n) {}
};
Edge E[MAXE];
int H[MAXN], cntE;
int n, m;
int g[MAXN];
int vis[MAXN];
int ans;
void clear() {
  cntE = 0;
  memset(H, -1, sizeof H);
  memset(vis, 0, sizeof vis);
}
void addedge(int u, int v) {
  E[cntE] = Edge(v, H[u]);
  H[u] = cntE++;
}
int pow(int a, int b) {
  long long res = 1, tmp = a;
  while (b) {
    if (b & 1) res = res * tmp % mod;
    tmp = tmp * tmp % mod;
    b >>= 1;
  }
  return res;
}
void dfs2(int u) {
  vis[u] = 1;
  for (int i = H[u]; ~i; i = E[i].n) {
    int v = E[i].v;
    if (!vis[v]) dfs2(v);
  }
}
void dfs(int cur) {
  if (cur == m + 1) {
    clear();
    for (int i = (2); i <= (m); ++i) addedge(g[i], i);
    dfs2(1);
    for (int i = (2); i <= (m); ++i)
      if (!vis[i]) return;
    ++ans;
    return;
  }
  for (int i = (1); i <= (m); ++i) {
    g[cur] = i;
    dfs(cur + 1);
  }
}
void solve() {
  ans = 0;
  dfs(2);
  ans = (long long)m * ans % mod * pow(n - m, n - m) % mod;
  printf("%d\n", ans);
}
int main() {
  while (~scanf("%d%d", &n, &m)) solve();
  return 0;
}
