#include <bits/stdc++.h>
using namespace std;
long long d[10] = {0, 1, 2, 9, 64, 625, 7776, 117649, 2097152};
long long fun(long long x) {
  long long y, ans = 1;
  for (y = 1; y <= x; ++y) {
    ans = (ans * x) % 1000000007;
  }
  return ans;
}
int main() {
  long long n, k, i, ans;
  cin >> n >> k;
  cout << (d[k] * fun(n - k)) % 1000000007 << endl;
  return 0;
}
