#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAXN = 1000;
int power(int b, int p) {
  if (p == 0) return 1;
  return b * 1LL * power(b, p - 1) % MOD;
}
int fact(int n) {
  if (n <= 0) return 1;
  return n * 1LL * fact(n - 1) % MOD;
}
int npr(int n, int r) {
  if (r > n) return 0;
  int ret = 1;
  for (int c = 0; c < r; c++) ret = ret * 1LL * (n - c) % MOD;
  return ret;
}
int ncr(int n, int r) {
  if (r > n) return 0;
  if (r == 0) return 1;
  return ncr(n - 1, r - 1) + ncr(n - 1, r);
}
int putKonN(int K, int N) {
  if (K == 0) return 1;
  int ret = 0;
  for (int take = 1; take <= K; take++)
    ret = (ret + power(N, take) * 1LL * ncr(K, take) % MOD * 1LL *
                     putKonN(K - take, take) % MOD) %
          MOD;
  return ret;
}
int n, k;
int main() {
  int c, c2;
  scanf("%d%d", &n, &k);
  int others = n - k;
  int factor = power(others, others);
  int ret = 0;
  for (int ones = 0; ones < k; ones++)
    ret = (ret + npr(k - 1, ones) * 1LL * putKonN(k - (1 + ones), ones + 1)) %
          MOD;
  printf("%d\n", ret * 1LL * factor % MOD);
  return 0;
}
