#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long powm(long long x, long long p) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = ans * 1ll * x % mod;
    x = 1ll * x * x % mod;
    p >>= 1;
  }
  return ans;
}
int t;
int main() {
  long long n, k;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  long long ans = powm(n - k, n - k);
  int i[k];
  long long ans2 = 0;
  fill(i, i + k, 0);
  int j = k - 1;
  while (1) {
    bool mark[8] = {false};
    j = k - 1;
    while (j >= 0 && i[j] == k) {
      i[j] = 0;
      i[j - 1]++;
      j--;
    }
    if (j < 0) return cout << (ans2 * ans) % mod, 0;
    t = 0;
    for (int cur = 0; cur < k; cur++)
      if (!cur || !i[cur] || !i[i[cur]] || !i[i[i[cur]]] || !i[i[i[i[cur]]]] ||
          !i[i[i[i[i[cur]]]]] || !i[i[i[i[i[i[cur]]]]]] ||
          !i[i[i[i[i[i[i[cur]]]]]]])
        t++;
    if (t == k) ans2++;
    if (ans == mod) ans = 0;
    i[k - 1]++;
  }
}
