#include <bits/stdc++.h>
#pragma GCC optmize("O3")
#pragma GCC target("sse4")
using namespace std;
using vi = vector<int>;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using vvi = vector<vi>;
constexpr ll mod = 1000000007;
constexpr ll inf = 0x3f3f3f3f;
inline ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
  }
  return res;
}
vector<vector<unsigned char> > initialPerm[2];
int n, K;
ll pref = 0;
vector<unsigned char> clayton;
vector<bool> reach(8, false);
inline bool checkPerm(vector<unsigned char>& vec) {
  unsigned int reach = 0;
  for (int(i) = (0); (i) < (K); ++(i)) {
    unsigned int mask = 0;
    mask |= (1 << i);
    int cur = i;
    while (1) {
      cur = vec[cur];
      if (cur == 0) {
        reach |= (1u << i);
        break;
      }
      if (reach & (1u << cur)) {
        reach |= (1u << i);
        break;
      }
      if ((mask & (1u << cur))) {
        return false;
      }
      mask |= (1u << cur);
    }
  }
  return true;
}
void doit(int k) {
  vector<unsigned char> nada;
  initialPerm[0].push_back(nada);
  for (int(i) = (1); (i) < (k + 1); ++(i)) {
    for (unsigned char num = 0; num < k; ++num) {
      for (const auto& perm : initialPerm[(i + 1) % 2]) {
        clayton = perm;
        clayton.push_back(num);
        if (i < k)
          initialPerm[i % 2].push_back(clayton);
        else
          pref += checkPerm(clayton);
      }
    }
    initialPerm[(i + 1) % 2].clear();
  }
}
inline bool checkPerm(const vector<unsigned char>& vec) {
  fill((reach).begin(), (reach).end(), false);
  for (int(i) = (0); (i) < (K + 1); ++(i)) {
    for (int(j) = (0); (j) < (K); ++(j)) {
      if (vec[j] == 0)
        reach[j] = true;
      else if (vec[j] != j && reach[vec[j]] == true)
        reach[j] = true;
    }
  }
  bool ok = true;
  for (int(j) = (0); (j) < (K); ++(j))
    if (reach[j] == false) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> K;
  doit(K);
  ll suf = powmod(n - K, n - K);
  pref = (pref * suf) % mod;
  cout << pref << endl;
  return 0;
}
