#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
long long n, k;
int p[10], vis[10];
long long res = 0;
void go(int at) {
  if (at >= k) {
    memset(vis, 0, sizeof vis);
    for (int i = 1; i < k; i++) {
      if (!vis[i]) {
        int at = i;
        while (at != 0) {
          vis[at] = 1;
          at = p[at];
          if (vis[at] == 1) return;
        }
        at = i;
        while (at != 0) {
          vis[at] = 2;
          at = p[at];
        }
      }
    }
    res++;
    return;
  }
  for (int i = 0; i < k; i++) {
    p[at] = i;
    go(at + 1);
    p[at] = k + 1;
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  go(0);
  for (int i = 0; i < n - k; i++) {
    res *= n - k;
    res %= mod;
  }
  cout << res << endl;
  return 0;
}
