#include <bits/stdc++.h>
using namespace std;
const int base = (int)1e9 + 7;
long long n, m;
long long binpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 1)
    return (binpow(a, n - 1) * a) % base;
  else {
    long long b = (binpow(a, n / 2)) % base;
    return (b * b) % base;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  long long ans = (binpow(n - m, n - m) * binpow(m, m - 1)) % base;
  cout << ans;
  return 0;
}
