#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n, k;
long long llpow(long long base, long long exp) {
  long long ret = 1LL;
  while (exp) {
    if (exp & 1) {
      ret *= base;
      ret %= mod;
    }
    base *= base;
    base %= mod;
    exp >>= 1;
  }
  return ret;
}
int main() {
  cin >> n >> k;
  long long ans = 1LL;
  ans *= llpow(k, k - 1);
  ans %= mod;
  ans *= llpow(n - k, n - k);
  ans %= mod;
  cout << ans << '\n';
  return 0;
}
