#include <bits/stdc++.h>
using namespace std;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
  return n | (1LL << i);
  ;
}
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
inline bool EQ2(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-7; }
int n, k;
bool vis[10];
int store[10];
long long recur(int index) {
  if (index == n) {
    for (int i = 0; i < n; ++i) {
      int j = i;
      memset(vis, 0, sizeof(vis));
      while (j != 0) {
        if (vis[j]) return 0;
        vis[j] = true;
        j = store[j];
      }
    }
    return 1;
  }
  long long ret = 0LL;
  for (int i = 0; i < n; ++i) {
    if (i == index && index != 0) continue;
    store[index] = i;
    ret += recur(index + 1);
    ret %= 1000000007;
  }
  return ret;
}
long long modPow(long long b, int p) {
  long long r = 1;
  while (p) {
    if (p & 1) r *= b, r %= 1000000007;
    b *= b, b %= 1000000007;
    p >>= 1;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> k >> n;
  long long ans = recur(0) * modPow(k - n, k - n);
  ans %= 1000000007;
  cout << ans;
  return 0;
}
