#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
  if (y == 0) return 1;
  long long int d = power(x, y / 2) % 1000000007;
  if (y % 2 == 0)
    return (d * d) % 1000000007;
  else
    return (((x * d) % 1000000007) * d) % 1000000007;
}
int bit[8];
int vis[8];
int tmp[8];
int n, k;
int cnt = 0;
int compreachable() {
  memset(vis, 0, sizeof vis);
  vis[0] = 2;
  int cnt1;
  for (int i = 1; i < cnt; i++) {
    if (vis[i] == 1) {
      continue;
    }
    cnt1 = 0;
    int idx = i;
    while (!vis[idx]) {
      if (idx == 0) break;
      tmp[cnt1++] = idx;
      vis[idx] = 1;
      idx = bit[idx];
    }
    if (idx == 0 || (vis[idx] == 2)) {
      for (int j = 0; j < cnt1; j++) {
        vis[tmp[j]] = 2;
      }
    } else {
      return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &k);
  long long int ans = power(n - k, n - k);
  if (k == 1) {
    printf("%lld\n", ans);
    return 0;
  }
  memset(bit, 0, sizeof bit);
  long long int tot = 0;
  int val;
  int flag;
  long long int len = power(k, k);
  for (int i = 0; i < len; i++) {
    cnt = 0;
    val = i;
    while (val > 0) {
      bit[cnt++] = val % k;
      val = val / k;
    }
    tot = tot + compreachable();
  }
  ans = (ans * tot) % 1000000007;
  printf("%lld\n", ans);
}
