#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long pwr[1007];
void pre() {
  for (long long i = 1; i <= 1002; i++) {
    pwr[i] = 1;
    for (int j = 1; j <= i; j++) pwr[i] = (pwr[i] * i) % mod;
  }
}
int vis[(1 << 10)], True;
long long dp[(1 << 10)];
int n, k;
long long bigmod(long long a, long long p) {
  if (p == 0) return 1;
  long long ret = bigmod(a, p / 2);
  if (p % 2 == 1) ret = (ret * a) % mod;
  return ret;
}
long long back(int bit, int cnt) {
  if (vis[bit] == True) return dp[bit];
  vis[bit] = True;
  dp[bit] = 0;
  if (bit == (1 << n) - 1) {
    return 0;
  }
  if (bit == (1 << k) - 1) return 0;
  for (int i = 1; i <= k; i++) {
    if (i == 1) {
      dp[bit] += (bigmod(cnt + 1, k - cnt - 1) * pwr[n - k]) % mod;
      dp[bit] %= mod;
    } else {
      if (bit & (1 << (i - 1)))
        ;
      else {
        dp[bit] += back((bit | (1 << (i - 1))), cnt + 1);
        dp[bit] %= mod;
      }
    }
  }
  return dp[bit];
}
int arr[20];
int cnt;
void re(int pos) {
  if (pos == k + 1) {
    bool pl = true;
    for (int i = 1; i <= k; i++) {
      bool plx = false;
      True++;
      vis[arr[i]] = True;
      int u = arr[i];
      while (u != 1) {
        u = arr[u];
        if (vis[u] == True) break;
        vis[u] = True;
      }
      if (u == 1) {
        plx = true;
      } else {
        pl = false;
        break;
      }
    }
    if (pl) cnt++;
    return;
  }
  for (int i = 1; i <= k; i++) {
    arr[pos] = i;
    re(pos + 1);
  }
}
int main() {
  pre();
  scanf("%d%d", &n, &k);
  long long ans = 1;
  if (k == 1)
    ans = 1;
  else if (k == 2)
    ans = 2;
  else if (k == 3)
    ans = 9;
  else if (k == 4)
    ans = 64;
  else if (k == 5)
    ans = 625;
  else if (k == 6)
    ans = 7776;
  else if (k == 7)
    ans = 117649;
  else if (k == 8)
    ans = 2097152;
  for (long long i = 1; i <= n - k; i++) ans = (ans * (n - k)) % mod;
  cout << ans << endl;
  return 0;
}
