#include <bits/stdc++.h>
using namespace std;
const int oo = (int)(1e9);
const long double PI = 3.141592653589793;
int PP = (int)1e9 + 7;
const int MAXN = 111111 * 2, MAXE = 111111;
template <typename TT>
void read(TT &x) {
  char ch;
  for (ch = getchar(); ch > '9' || ch < '0'; ch = getchar())
    ;
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
}
int n, m, a[9], ans;
void dfs(int u) {
  if (u > n) {
    bool ok = 1;
    for (int i = 1; i <= n; i++) {
      int x = i;
      int v[9];
      memset(v, 0, sizeof(v));
      ;
      v[x] = 1;
      for (;;) {
        if (v[a[x]] || x == 1) break;
        v[a[x]] = 1;
        x = a[x];
      }
      ok &= v[1];
    }
    if (ok) {
      ans += ok;
    }
  } else
    for (int i = 1; i <= n; i++) {
      a[u] = i;
      dfs(u + 1);
    }
}
int pow(int xx, int y) {
  int x = 1, t = xx;
  for (; y; y /= 2) {
    if (y & 1) x = 1LL * x * t % PP;
    t = 1LL * t * t % PP;
  }
  return x;
}
void Init() {
  {
    read(n);
    read(m);
  };
  ans = 1LL * pow(m, m - 1) * pow(n - m, n - m) % PP;
  cout << ans;
}
int main() { Init(); }
