#include <bits/stdc++.h>
using namespace std;
const int M = 6 * 1e5;
const long long Q = 1e9 + 7;
int ans;
int a[10];
bool used[10];
void dfs(int i) {
  used[i] = true;
  if (!used[a[i]]) dfs(a[i]);
}
void gen(int i, int n) {
  if (i == n + 1) {
    bool ok = true;
    for (int j = 1; j <= n; j++) {
      for (int f = 1; f <= n; f++) used[f] = false;
      dfs(j);
      if (!used[1]) {
        ok = false;
        break;
      }
    }
    if (ok) ans++;
    return;
  }
  for (int j = 1; j <= n; j++) {
    a[i] = j;
    gen(i + 1, n);
  }
}
int cnt(int n) {
  ans = 0;
  gen(1, n);
  int tmp = ans;
  return tmp;
}
int main() {
  srand(time(NULL));
  int n, k;
  scanf("%d%d", &n, &k);
  long long x = 1;
  for (int i = 0; i < (n - k); i++) x = (x * (n - k)) % Q;
  long long y = cnt(k);
  cout << (x * y) % Q;
  cerr << clock() / (CLOCKS_PER_SEC + 0.);
  return 0;
}
