#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30);
const double PI = acos(-1.0);
const double EPS = 1e-11;
const long long MOD = 1000000007;
int n, k;
long long power(int x, int a) {
  long long tmp;
  if (a == 0) return 1;
  if (a == 1) return x;
  tmp = power(x, a / 2);
  if (a % 2)
    return (tmp * tmp) % MOD * x % MOD;
  else
    return (tmp * tmp) % MOD;
}
int main() {
  long long res;
  int t;
  scanf("%d%d", &n, &k);
  res = power(k, k - 1);
  res = res % MOD * power(n - k, n - k) % MOD;
  printf("%I64d\n", res);
  return 0;
}
