#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
    b /= 2;
    a = ((a % m) * (a % m)) % m;
  }
  return ans % m;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  long long ans = 1;
  ans *= (pow(k, k - 1, (long long)(1000 * 1000 * 1000 + 7)));
  ans %= (long long)(1000 * 1000 * 1000 + 7);
  ans *= (pow(n - k, n - k, (long long)(1000 * 1000 * 1000 + 7)));
  ans %= (long long)(1000 * 1000 * 1000 + 7);
  cout << ans;
}
