#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct mint {
  int x;
  mint() : x(0) {}
  mint(int s) {
    x = s;
    if (x < MOD && x >= 0) return;
    x %= MOD;
    if (x < 0) x += MOD;
  }
  mint(long long s) {
    int ts = s % MOD;
    if (ts < 0) ts += MOD;
    x = ts;
  }
  mint& operator+=(mint t) {
    if ((x += t.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(mint t) {
    if ((x += MOD - t.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(mint t) {
    x = (long long)x * t.x % MOD;
    return *this;
  }
  mint& operator/=(mint t) { return *this *= t.inv(); }
  mint operator-() const {
    if (x) return MOD - x;
    return 0;
  }
  mint operator+(mint t) const { return mint(*this) += t; }
  mint operator-(mint t) const { return mint(*this) -= t; }
  mint operator*(mint t) const { return mint(*this) *= t; }
  mint operator/(mint t) const { return mint(*this) /= t; }
  mint pow(long long k) const {
    mint r = 1, a = x;
    for (; k; k >>= 1, a *= a)
      if (k & 1) r *= a;
    return r;
  }
  mint inv() const { return mint(x).pow(MOD - 2); }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  mint nn = n - k, kk = k;
  cout << (nn.pow(n - k) * kk.pow(k - 1)).x << '\n';
  return 0;
}
