#include <bits/stdc++.h>
using namespace std;
int v[9], p[9], n, m, i, mod = 1000000007;
long long ans;
bool go(int x) {
  if (v[x] == 1) return 1;
  if (v[x] == -1) return 0;
  v[x] = -1;
  if (go(p[x])) return v[x] = 1;
  return 0;
}
void dfs(int x) {
  int i;
  if (x > m) {
    memset(v, 0, sizeof(v));
    v[1] = 1;
    for (i = 2; i <= m; i++)
      if (!go(i)) break;
    ans += i > m;
    return;
  }
  for (i = 1; i <= m; i++)
    if (x == 1 || i != x) {
      p[x] = i;
      dfs(x + 1);
    }
}
int main() {
  cin >> n >> m;
  dfs(1);
  for (i = 1; i <= n - m; i++) ans = ans * (n - m) % mod;
  cout << ans << endl;
}
