#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return to_string(string(1, c)); }
string to_string(vector<bool> v) {
  string res = "{";
  int sz = (int)v.size();
  for (int i = 0; i < sz; i++) {
    if (i > 0) res += ", ";
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& a : v) {
    if (!first) res += ", ";
    first = false;
    res += to_string(a);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename A, typename... B>
void debug_out(A a, B... b) {
  cerr << to_string(a);
  if (sizeof...(b)) cerr << ", ";
  debug_out(b...);
}
const int MOD = 1000000007;
int modpow(int a, int p) {
  if (p == 0) return 1;
  int h = modpow(a, p / 2);
  h = (h * 1LL * h) % MOD;
  if ((p & 1) == 1) h = (h * 1LL * a) % MOD;
  return h;
}
int fin;
int n, k;
vector<int> to;
int solve(int mask) {
  if (mask == fin) {
    for (int i = 1; i < k; i++) {
      int curr = i;
      vector<bool> vis(k);
      while (curr != 0 && !vis[curr]) {
        vis[curr] = true;
        curr = to[curr];
      }
      if (curr != 0) return 0;
    }
    return 1;
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    int cmask = 1 << i;
    if ((mask & cmask) == 0) {
      for (int j = 0; j < k; j++) {
        if (i == j) continue;
        to[i] = j;
        ans += solve(mask | cmask);
        if (ans >= MOD) ans -= MOD;
        to[i] = -1;
      }
    }
  }
  return ans;
}
int main() {
  cin.tie(0);
  cin.exceptions(cin.failbit);
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  int ans = modpow(n - k, n - k);
  int left = modpow(k, k - 1);
  cout << (ans * 1LL * left) % MOD << '\n';
}
