#include <bits/stdc++.h>
using namespace std;
int check(int a[], int k) {
  bool vis[10] = {0};
  int p, cnt;
  p = 0;
  vis[0] = 1;
  cnt = 1;
  while (1) {
    p = a[p];
    if (vis[p]) break;
    vis[p] = 1;
    cnt++;
  }
  return cnt == k;
}
int rec(int a[], int pos, int k) {
  int i;
  if (pos == k) {
    bool vis[10] = {0};
    int p = 0;
    vis[p] = 1;
    while (1) {
      p = a[p];
      if (vis[p]) {
        if (p != 0) return 0;
        break;
      }
      vis[p] = 1;
    }
    for (i = 0; i < k; i++) {
      if (vis[i]) continue;
      int cnt = 1;
      p = i;
      while (cnt <= k) {
        p = a[p];
        if (vis[p]) break;
        cnt++;
      }
      if (cnt > k) return 0;
    }
    return 1;
  }
  int ret = 0;
  for (i = 0; i < k; i++) {
    a[pos] = i;
    ret += rec(a, pos + 1, k);
  }
  return ret;
}
long long power(int a, int k) {
  if (k == 0) return 1;
  if (k == 1) return a;
  long long ret = power(a, k / 2);
  ret = (ret * ret) % 1000000007;
  if (k & 1) ret = (ret * a) % 1000000007;
  return ret;
}
int main() {
  int n, k, i, a[10];
  cin >> n >> k;
  for (i = 0; i < k; i++) {
    a[i] = i;
  }
  long long ans = 0;
  ans = rec(a, 0, k);
  ans = (ans * power(n - k, n - k)) % 1000000007;
  cout << ans << endl;
  return 0;
}
