#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << "\b\b]\n"; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << H << ", ";
  dbg_out(T...);
}
const int mod = 1e9 + 7;
vector<int> A;
long long n, k, cnt;
bool check() {
  for (int i = 0; i < k; ++i) {
    int curr = i;
    for (int j = 0; j < k and curr != 0; ++j) {
      curr = A[curr];
    }
    if (curr != 0) return false;
  }
  return true;
}
void go(int pos) {
  if (pos >= k) {
    if (check()) cnt++;
    return;
  }
  for (int i = 0; i < k; ++i) {
    A[pos] = i;
    go(pos + 1);
  }
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  A.resize(k);
  iota(A.begin(), A.end(), 0);
  go(0);
  long long ans = (cnt * power(n - k, n - k)) % mod;
  cout << ans;
  return 0;
}
