#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const double pi = 3.1415926;
const long double eps = 1e-9;
const int N = (int)1e5 + 5;
const int INF = (int)1e9 + 10;
const double EPS = 0.00001;
int main() {
  int n, k;
  cin >> n >> k;
  long long r1 = 1, r2 = 1;
  for (int i = 0; i < k - 1; i++) {
    r1 = (r1 * k) % 1000000007;
  }
  for (int i = 0; i < n - k; i++) {
    r2 = (r2 * (n - k)) % 1000000007;
  }
  long long res = (r1 * r2) % 1000000007;
  cout << res;
}
