#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define PLL pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vll (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
ll p = 1e9+7;
// ll p = 998244353;
// n do -> n*pi/180
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

ll f(ll x,ll n){
  if(n==0)return 1;
  if(n==1)return x;
  if(n%2)return x*f(x,n-1)%p;
  ll r=f(x,n/2);
  return r*r%p;
}

int main(){
  cci(n,k);

  ll ans=(k-1)*f(k-2,n-1)%p;
  co(ans);
}
                                             //"IN THE NAME OF ALLAH"//



#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

// --------------------------------------------------------------------------------------------------------------->

#define el << '\n'
#define pb push_back
#define PI 3.141592653589793238
#define _test_ int _ ; cin >> _ ; while( _-- )
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)

// --------------------------------------------------------------------------------------------------------------->

int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
const ll infLL = 1e17+123;
const ll inf = 1e16+7;
const ll mod = 1e9+7;
const ll mx = 1e6+123;

// --------------------------------------------------------------------------------------------------------------->
ll n,a[mx],Q[mx];

void _case_()
{
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    ll ans=1 ;
    for(int i=1;i<=n;i++)
    {
        Q[i]=(a[i]-a[i-1]+1);
    }
    for(int i=1;i<=n;i++)
    {
        ans=ans*Q[i];
        ans%=mod;
    }
    cout << ans el;
}

int main()
{
    optimize();
    //_test_
    _case_();
    return 0;
}
//                                                                                                     _𝓷𝓸𝓸𝓫𝓶𝓪𝓼𝓽𝓮𝓻_