#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[9] = {0};
bool is_good(int x, int depth) {
  if (depth == 0) return false;
  if (x == 0) return true;
  return is_good(a[x], depth - 1);
}
bool find_next(int num) {
  bool found = false;
  bool good = true;
  for (int i = 1; i < k; i++) {
    a[i] = num % k;
    num /= k;
    if (a[i] != 0) found = true;
  }
  return found;
}
long long mod = 1000000007;
int main() {
  scanf("%d%d", &n, &k);
  long long sum = 1;
  int i = 0;
  while (find_next(++i)) {
    bool good = true;
    for (int i = 1; i < k; i++) {
      if (!is_good(i, 9)) {
        good = false;
      }
    }
    if (good) {
      sum++;
    }
  }
  sum = (sum * (k)) % mod;
  if (n > k) {
    for (int i = 0; i < n - k; i++) {
      sum = (sum * (n - k)) % mod;
    }
  }
  cout << sum << endl;
  return 0;
}
