#include <bits/stdc++.h>

#define ll long long
#define lp(i,n) for(int i=0; i<n; i++)
#define pb push_back
const long double pi=3.141592654;
#define OSOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll n,m,cnt=0,mod = 1e9+7;
bool cat[1000000] = {};
bool vis[1000000] = {};
vector<vector<int>>all;
vector<int>vec;
	vector<int>v;
int dx[8]={0,0,1,-1,1,-1,1,-1};
int dy[8]={1,-1,0,0,1,-1,-1,1};
bool valid(int r,int c)
{
	return r >= 0 && c >= 0 && r < n && c < m ;
}

void solve(int index,int k)
{
	if(k == 0)
	{
		all.pb(v);
		return;
	}
	for(int i=index; i<=n-k; i++)
	{
		v.pb(vec[i]);
		solve(i+1,k-1);
		v.pop_back();
	}
}
int main()
{
	OSOS
	cin>>n>>m;
	ll ans = 0;
	vec.resize(n);
	lp(i,n)cin>>vec[i];
	solve(0,m);
	for(int i=0; i<(int)all.size(); i++)
	{
		int max =*max_element(all[i].begin(),all[i].end());
		int min =*min_element(all[i].begin(),all[i].end());
		ans = (ans%mod +(max - min)%mod)%mod;
	}
	cout<<ans;

}

