#include <bits/stdc++.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, -1, 1, 1, -1, 1, -1};
char dc[4] = {'N', 'S', 'W', 'E'};
int main() {
  long long int n, k, ans = 1;
  cin >> n >> k;
  for (int i = 1; i <= n - k; i++)
    ans = (ans % 1000000007 * (n - k) % 1000000007) % 1000000007;
  for (int i = 1; i < k; i++)
    ans = (ans % 1000000007 * k % 1000000007) % 1000000007;
  cout << ans << endl;
}
