#include <bits/stdc++.h>
using namespace std;
int n, k;
long long ans, f[1111][1111], C[1111][1111];
int main() {
  for (int i = 0; i <= 1001; i++)
    for (int j = 0; j <= i; j++)
      if (j == 0 || j == i)
        C[i][j] = 1;
      else
        C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 1000000007;
  cin >> n >> k;
  ans = 1;
  ans = (ans * k) % 1000000007;
  for (int i = 0; i < n - k; i++) ans = (ans * (n - k)) % 1000000007;
  f[1][1] = 1;
  for (int i = 0; i < k; i++)
    for (int j = 1; j <= i; j++) {
      long long q = 1;
      for (int l = 1; l <= k - i; l++) {
        q = q * j % 1000000007;
        f[i + l][l] = (f[i + l][l] +
                       f[i][j] * C[k - i][l] % 1000000007 * q % 1000000007) %
                      1000000007;
      }
    }
  long long aa = 0;
  for (int i = 1; i <= k; i++) aa = (aa + f[k][i]) % 1000000007;
  ans = ans * aa % 1000000007;
  cout << ans << endl;
  return 0;
}
