#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
using namespace std;
const int maxn = 1000001;
const int mod = 1000000007;
int binpow(long long a, int n) {
  long long res = 1;
  while (n) {
    if (n & 1) res *= a, res %= mod;
    a *= a, a %= mod;
    n >>= 1;
  }
  return res;
}
int binpow2(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
int p[8];
short mask[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
bool able(int d, short k) {
  if (k == 8)
    for (int i = (0); i < (k); i++)
      p[i] = ((d & ((1 << (3 * (i + 1))) - 1)) >> (3 * i)), mask[i] = -1;
  else
    for (int i = (0); i < (k); i++)
      p[i] = (d % binpow2(k, i + 1)) / binpow2(k, i), mask[i] = -1;
  for (int i = (0); i < (k); i++) {
    if (mask[i] != -1) continue;
    int cur = i;
    mask[cur] = i;
    cur = p[cur];
    while (cur != 0) {
      mask[cur] = i;
      int t = p[cur];
      if (t == 0 || (mask[t] < i && mask[t] != -1)) break;
      if (mask[t] == i) return 0;
      cur = t;
    }
  }
  return true;
}
int g1(int k) {
  int b = 1;
  for (int i = (0); i < (k); i++) b *= k;
  int cnt = 0;
  for (int i = (0); i < (b); i++)
    if (able(i, k)) cnt++;
  return cnt;
}
int main() {
  int n, k;
  cin >> n >> k;
  cout << (long long)g1(k) * binpow(n - k, n - k) % mod << endl;
}
