#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fixAngle(double A) { return A > 1 ? 1 : (A < -1 ? -1 : A); }
double dcmp(double a, double b) {
  return fabs(a - b) < 1e-6 ? 0 : a > b ? 1 : -1;
}
long long n, k;
const int MOD = 1000000007;
vector<int> perm;
int dp[10];
int check_path(int idx) {
  if (idx == 0) {
    return 1;
  }
  if (~dp[idx]) return dp[idx];
  dp[idx] = 0;
  return dp[idx] = check_path(perm[idx]);
}
int check() {
  if (perm[0] >= k) {
    return 0;
  }
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < perm.size(); i++) {
    if (check_path(i) == 0) return 0;
  }
  return 1;
}
long long count_ways(int idx) {
  if (idx == k) {
    return check();
  }
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    perm.push_back(i);
    ans += count_ways(idx + 1);
    ans %= MOD;
    perm.pop_back();
  }
  return ans;
}
int main() {
  cin >> n >> k;
  long long sum = count_ways(0);
  long long m = (n - k) % MOD;
  for (int i = k; i < n; i++) {
    sum *= m;
    sum %= MOD;
  }
  cout << sum << endl;
}
