#include <bits/stdc++.h>
using namespace std;
long long int modPow(long long int a, long long int x) {
  long long int res = 1;
  while (x > 0) {
    if (x & 1) {
      res = (res * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    x >>= 1;
  }
  return res;
}
long long int modInverse(long long int a) { return modPow(a, 1000000007 - 2); }
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int ans1 = modPow(k, k - 1);
  k = n - k;
  long long int ans2 = modPow(k, k);
  ans2 = (ans1 * ans2) % 1000000007;
  cout << ans2 << endl;
  return 0;
}
