#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, m, s;
int a[9];
int ans[9];
int func(int x) {
  if (ans[x] != -1) return ans[x];
  ans[x] = 0;
  ans[x] = func(a[x]);
  return ans[x];
}
bool can() {
  for (int i = 0; i < 9; i++) ans[i] = -1;
  ans[1] = 1;
  for (int i = 2; i <= m; i++)
    if (!func(i)) return false;
  return true;
}
void f(int x) {
  if (x == m + 1) {
    s += can();
    return;
  }
  for (int i = 1; i <= m; i++) {
    a[x] = i;
    f(x + 1);
  }
}
int main() {
  cin >> n >> m;
  f(1);
  for (int i = m + 1; i <= n; i++)
    s = ((long long)s * (long long)(n - m)) % MOD;
  cout << s << endl;
  return 0;
}
