#include <bits/stdc++.h>
using namespace std;
int arr[9];
int ans = 0;
bool correct(int k) {
  for (int i = 2; i <= k; i++) {
    int cur = i;
    int steps = 0;
    bool done = 0;
    while (steps < 10) {
      cur = arr[cur];
      steps++;
      if (cur == 1) {
        done = 1;
        break;
      }
    }
    if (!done) return 0;
  }
  return 1;
}
void recurse(int i, int k) {
  if (i == k + 1) {
    if (correct(k)) ans++;
    return;
  }
  for (int j = 1; j <= k; j++) {
    if (j == i) continue;
    arr[i] = j;
    recurse(i + 1, k);
  }
}
int solve(int k) {
  if (k == 1) return 1;
  ans = 0;
  recurse(2, k);
  return k * ans;
}
long long fpow(int a, int b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = x * y;
      if (x > 1000000007) x %= 1000000007;
    }
    y = y * y;
    if (y > 1000000007) y %= 1000000007;
    b /= 2;
  }
  return x;
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long long ans = (fpow(k, k - 1) * fpow(n - k, n - k)) % 1000000007;
  cout << ans << "\n";
  return 0;
}
