#include <bits/stdc++.h>
using namespace std;
void gt(int &a, int b) {
  if (a < b) a = b;
}
string n2s(int a) {
  stringstream ss;
  ss << a;
  return ss.str();
}
string getKey(int v, int h) { return n2s(v) + "-" + n2s(h); }
long long Pow(long long x, long long y) {
  long long ans = 1;
  for (; y; y /= 2) {
    if (y & 1) ans = ans * x % 1000000007;
    x = x * x % 1000000007;
  }
  return ans;
}
int main() {
  long long a[9]{0, 1, 2, 9, 64, 625, 7776, 117649, 2097152};
  long long n, k, ans;
  cin >> n >> k;
  ans = a[k] * Pow(n - k, n - k) % 1000000007;
  cout << ans << endl;
  return 0;
}
