#include <bits/stdc++.h>
using namespace std;
int64_t power(int x) {
  if (x == 0 || x == 1) return 1;
  int64_t rez = 1;
  for (int i = 1; i <= x; ++i) rez = (rez * x) % 1000000007;
  return rez;
}
int v[9];
int64_t r = 0;
bool visit[9];
int rev[9][9];
int sizerev[9];
bool good_sol(int k) {
  sizerev[1] = 0;
  for (int i = 2; i <= k; ++i) {
    sizerev[i] = 0;
    visit[i] = false;
  }
  visit[1] = false;
  for (int i = 2; i <= k; ++i) {
    rev[v[i]][sizerev[v[i]]++] = i;
  }
  int nrgood = 0;
  queue<int> q;
  q.push(1);
  int x;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    visit[x] = true;
    nrgood++;
    for (int i = 0; i < sizerev[x]; i++)
      if (!visit[rev[x][i]]) q.push(rev[x][i]);
  }
  return nrgood == k;
}
void bkt(int j, int k) {
  if (j > k) {
    if (good_sol(k)) r++;
    return;
  }
  for (int i = 1; i <= k; ++i) {
    if (i == j) continue;
    v[j] = i;
    bkt(j + 1, k);
  }
}
int64_t nr(int k) {
  if (k == 1) return 1;
  bkt(2, k);
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  if (k == 1 && n == 1) {
    cout << "1" << endl;
    return 0;
  }
  if (k == n) {
    int64_t rez = (nr(n) * n) % 1000000007;
    cout << rez << endl;
    return 0;
  }
  if (k == 1) {
    cout << power(n - k) << endl;
    return 0;
  }
  int64_t rez = (nr(k) * k) % 1000000007;
  for (int i = 1; i <= n - k; ++i) rez = (rez * (n - k)) % 1000000007;
  cout << rez << endl;
  return 0;
}
