#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int tag[10];
int vis[10];
long long fast_pow(long long a, long long b) {
  long long ans = 1;
  a = a % M;
  while (b) {
    if (b % 2) ans = (ans * a) % M;
    b /= 2;
    a = (a * a) % M;
  }
  return ans;
}
bool judge(int k) {
  int pos;
  for (int i = 1; i <= k; ++i) {
    memset(vis, 0, sizeof(vis));
    pos = i;
    while (true) {
      vis[pos] = 1;
      pos = tag[pos];
      if (pos == 1) break;
      if (vis[pos] == 1) return false;
    }
  }
  return true;
}
long long full(int pos, int k) {
  long long ans = 0;
  for (int i = 1; i <= k; ++i) {
    tag[pos] = i;
    if (pos == k) {
      if (judge(k)) {
        ans = (ans + 1) % M;
      }
    } else {
      ans = (ans + full(pos + 1, k)) % M;
    }
  }
  return ans;
}
int main() {
  long long n, k;
  long long ans;
  while (scanf("%lld%lld", &n, &k) == 2) {
    ans = fast_pow(n - k, n - k);
    memset(tag, 0, sizeof(tag));
    ans = (ans * full(1, k)) % M;
    printf("%lld\n", ans);
  }
  return 0;
}
