#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10, M = 1e9 + 7;
long long dp[N], c[N][N], n, rch, power[N], ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> rch;
  power[0] = 1;
  for (int i = 0; i < n; i++) {
    c[i][0] = 1;
    power[i + 1] = (power[i] * (n - rch)) % M;
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  }
  dp[1] = dp[0] = 1;
  for (int i = 2; i <= rch; i++) {
    dp[i] = (dp[i - 1] * (i - 1)) % M;
    for (int j = 0; j < i - 2; j++)
      dp[i] = (dp[i] +
               (c[i - 2][j] * dp[j + 1] % M) * ((j + 1) * dp[i - 1 - j] % M)) %
              M;
  }
  ans = (rch * (dp[rch] * power[n - rch]) % M) % M;
  cout << ans;
}
