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