#include <bits/stdc++.h>
using namespace std;
template <class Ta, class Tb>
inline Tb cast(Ta a) {
  stringstream ss;
  ss << a;
  Tb b;
  ss >> b;
  return b;
};
const double EPS = 1e-9;
const int INF = 1000000000;
const int diri[8] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dirj[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long long T[9] = {0LL,   1LL,    2LL,      9LL,      64LL,
                        625LL, 7776LL, 117649LL, 2097152LL};
const long long mod = 1000000007LL;
long long pot(long long a, long long b) {
  if (b == 0) return 1;
  long long first = pot(a, b / 2);
  first = (first * first) % mod;
  if (b & 1) first = (first * a) % mod;
  return first;
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long p = pot(n - k, n - k);
  cout << (T[k] * p) % mod << endl;
}
