#include <bits/stdc++.h>
using namespace std;
const int M = 10 + 10;
int dp[M][M];
long long int ans = 0;
int a[M];
long long int mod = 1000000000 + 7;
vector<int> ind[M];
int flag[M];
void dfs(int num, int k) {
  if (num == k + 1) {
    for (int i = 1; i <= k; i++) {
      flag[i] = 0;
      ind[i].clear();
    }
    for (int i = 2; i <= k; i++) {
      ind[a[i]].push_back(i);
    }
    queue<int> q;
    q.push(1);
    flag[1] = 1;
    while (!q.empty()) {
      int node = q.front();
      q.pop();
      for (int i = 0; i < ind[node].size(); i++) {
        int nxt = ind[node][i];
        if (flag[nxt] == 0) {
          q.push(nxt);
          flag[nxt] = 1;
        }
      }
    }
    int cnt = 0;
    for (int i = 1; i <= k; i++) {
      cnt += flag[i];
    }
    if (cnt == k) {
      ans++;
    }
  } else {
    int s = 1;
    if (num == 1) {
      s = k;
    }
    for (int i = s; i <= k; i++) {
      a[num] = i;
      dfs(num + 1, k);
    }
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  dfs(1, k);
  ans = (ans * k) % mod;
  for (int i = 1; i <= n - k; i++) {
    ans = (ans * (n - k)) % mod;
  }
  cout << ans << endl;
  return 0;
}
