#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    T t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
int k;
int ar[10];
int cnt = 0;
int vis[10], val[10];
int dfs2(int v) {
  if (v == 1) return val[v] = 1;
  if (vis[v] == 1) return val[v];
  vis[v] = 1;
  val[v] = dfs2(ar[v]);
}
void dfs(int l) {
  if (l > k) {
    int x, f = 0;
    memset(vis, 0, sizeof vis);
    memset(val, 0, sizeof val);
    for (x = 2; x <= k; x++) dfs2(x);
    dfs2(ar[1]);
    for (x = 1; x <= k; x++)
      if (val[x] == 0) f++;
    if (f == 0) cnt++;
    return;
  }
  for (int x = 1; x <= k; x++) {
    ar[l] = x;
    dfs(l + 1);
  }
}
long long arr[10] = {1ll, 2ll, 9ll, 64ll, 625ll, 7776ll, 117649ll, 2097152ll};
int main() {
  long long a, b, c, d, e, f, g, h, x, y, z;
  cin >> a >> b;
  a = a - b;
  long long ret = 1;
  for (x = 1; x <= a; x++) ret = (ret * a) % 1000000007;
  ret = (ret * arr[b - 1]) % 1000000007;
  cout << ret << endl;
}
