#include <bits/stdc++.h>
using namespace std;
const int maxn = 1200;
int a[maxn];
int n, m, k, x, y;
vector<int> adlist[maxn];
bool visited[maxn];
int vt[maxn];
bool is[maxn];
void input() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adlist[a].push_back(b);
    adlist[b].push_back(a);
  }
}
int t = 0;
int numb = 0;
int nn[maxn];
void dfs(int root) {
  visited[root] = 1;
  nn[root] = t++;
  for (int i = 0; i < adlist[root].size(); i++) {
    if (!visited[adlist[root][i]]) {
      vt[adlist[root][i]] = !vt[root];
      dfs(adlist[root][i]);
    } else {
      if (vt[root] == vt[adlist[root][i]] && nn[root] < nn[adlist[root][i]]) {
        numb++;
      }
    }
  }
}
void find() {
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      vt[i] = 0;
      dfs(i);
    }
  }
  cout << numb << endl;
}
int main() {
  int n, k;
  cin >> n >> k;
  long long sum1 = 1;
  for (int i = 1; i <= k - 1; i++) {
    sum1 = (sum1 * (long long)k) % 1000000007;
  }
  long long gh = n - k;
  for (long long i = k + 1; i <= n; i++) {
    sum1 = (sum1 * gh) % 1000000007;
  }
  cout << sum1 << endl;
}
