#include <bits/stdc++.h>
using namespace std;
const unsigned long int MOD = 1000000007;
unsigned long int n, k, answer;
unsigned long int multiplyMod(unsigned long int a, unsigned long int b) {
  if (!a || !b) {
    return 0;
  }
  if (a & 1) {
    return (b + multiplyMod(a - 1, b)) % MOD;
  }
  return (multiplyMod(a / 2, b) * 2) % MOD;
}
unsigned long int pow(unsigned long int base, unsigned long int power) {
  return (power == 0) ? 1
         : (power == 1)
             ? base % MOD
             : multiplyMod((base % MOD), (pow(base, power - 1) % MOD));
}
void init() { scanf("%lu%lu", &n, &k); }
void solve() {
  answer = multiplyMod(pow(k, k - 1) % MOD, pow(n - k, n - k) % MOD);
}
void output() { printf("%lu", answer); }
int main() {
  init();
  solve();
  output();
  return 0;
}
