#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const string LN = "\n";
const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = (int)2e9 + 7;
const long long LINF = (long long)9e18 + 7;
bool insert(int k, int x1, int x2) { return (k >= x1 && k <= x2); }
const int MAXN = 60007;
const long long MOD = 1e9 + 7;
int n, k;
bool was[10];
long long ans = 0;
void ok(vector<int> &q) {
  for (int i = 1; i < q.size(); i++) {
    for (int i = 0; i < 9; i++) was[i] = 0;
    int uk = i;
    while (1) {
      if (uk < i) break;
      if (was[uk]) return;
      was[uk] = 1;
      uk = q[uk] - 1;
    }
  }
  ans++;
}
void gen(vector<int> &q) {
  if (q.size() == k) {
    ok(q);
  } else {
    for (int i = 1; i <= k; i++) {
      q.push_back(i);
      gen(q);
      q.pop_back();
    }
  }
}
long long bin(long long a, long long k) {
  if (k == 1) return a;
  if (k % 2 == 0) {
    long long b = bin(a, k / 2);
    return (b * b) % MOD;
  } else {
    return (a * bin(a, k - 1)) % MOD;
  }
}
const bool is_testing = 0;
int main() {
  srand(time(NULL));
  if (is_testing) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  cin >> n >> k;
  vector<int> q;
  gen(q);
  if (n - k == 0)
    cout << ans;
  else {
    ans = (ans * bin(n - k, n - k)) % MOD;
    cout << ans;
  }
}
