#include <bits/stdc++.h>
using namespace std;
long long k, n, ans, used[100], a[100], v[10];
bool go(int x) {
  if (used[x] == 1) return 1;
  if (used[x] == 2) return 0;
  used[x] = 2;
  if (go(a[x])) {
    used[x] = 1;
    return 1;
  }
  return 0;
}
void f(long long x) {
  if (x > k) {
    for (long long i = 1; i <= 10; i++) used[i] = 0;
    used[1] = 1;
    long long i;
    for (i = 2; i <= k; i++)
      if (!go(i)) break;
    if (i > k) ans++;
    return;
  }
  for (long long i = 1; i <= k; i++) a[x] = i, f(x + 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  f(1);
  for (long long i = 1; i <= n - k; i++) ans *= (n - k), ans %= (1000000007);
  cout << ans;
}
