#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int64_t MOD = 1e9 + 7;
int n, k, p[8], ans;
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool good(int i) {
  bool v[8]{};
  while (!v[i]) {
    if (i == 0) return true;
    v[i] = true;
    i = p[i];
  }
  return false;
}
void run(int i) {
  if (i == k) {
    for (int i = 0; i < k; i++) {
      if (!good(i)) return;
    }
    ans++;
  } else {
    for (int j = 0; j < k; j++) {
      if (j == 0 || j != i) {
        p[i] = j;
        run(i + 1);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
  cin >> n >> k;
  run(0);
  cout << ans * modpow((int64_t)(n - k), (int64_t)(n - k), MOD) % MOD << endl;
  return 0;
}
