#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int(i) = 0; (i) < (((int)((t).size()))); ++(i)) s << t[i] << " ";
  return s;
}
vector<int> adj[10];
bool seen[10];
int q[10];
const int mod = 1000000007;
int main() {
  int(n), (k);
  scanf("%d %d", &(n), &(k));
  int rest = n - k;
  long long res = k;
  for (int(u) = 0; (u) < (rest); ++(u)) res = (res * rest) % mod;
  int ukl = 0;
  int limit = 1 << (3 * (k - 1));
  for (int(mask) = 0; (mask) < (limit); ++(mask)) {
    int val[10];
    for (int(i) = 0; (i) < (k - 1); ++(i)) val[i + 1] = (mask >> (3 * i)) & 7;
    bool zle = 0;
    for (int(i) = 1; (i) <= (k - 1); ++(i))
      if (val[i] > k - 1) zle = 1;
    if (zle) continue;
    for (int(i) = (0); (i) <= (k - 1); ++i) adj[i].clear();
    for (int(i) = 1; (i) <= (k - 1); ++(i)) adj[val[i]].push_back(i);
    memset(seen, 0, sizeof(seen));
    int qs = 0, qe = 1;
    q[0] = 0;
    seen[0] = 1;
    while (qs < qe) {
      int v = q[qs++];
      for (typeof(adj[v].begin()) it = adj[v].begin(); it != adj[v].end(); it++)
        if (!seen[*it]) {
          seen[*it] = 1;
          q[qe++] = *it;
        }
    }
    for (int(i) = 1; (i) <= (k - 1); ++(i))
      if (seen[i] == 0) zle = 1;
    if (zle) continue;
    ukl++;
  }
  res = (res * ukl) % mod;
  if (res < 0) res += mod;
  pisz(res);
}
