#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

const long long int mod=1000000007,INF=9999999999999;

long long int dp[5500][5500]={};
long long int LDSmemo=0,dp2[200010],LISs[200005];

long long int GyakuLIS(long long int n,long long int s[]){
	LDSmemo=0;
	for(long long int i=0;i<n;i++){
		dp2[i]=INF;
		LISs[i]=s[n-i];
	}
	for(long long int i=0;i<n;i++){
		*lower_bound(dp2,dp2+n,LISs[i])=LISs[i];
	}
    
	return lower_bound(dp2,dp2+n,INF)-dp2;
}

long long int kaijyou[200005]={1};


long long int ruijyou(long long int a,long long int b){
	if(b==0)return 1;
	long long int res=ruijyou(a*a%mod,b/2);
	if(b & 1)res=res*a%mod;
	return res;
}
long long int combination(long long int a,long long int b){
	long long int res=kaijyou[a]*ruijyou(kaijyou[b],mod-2)%mod;
	res=res*ruijyou(kaijyou[a-b],mod-2)%mod;
	return res;
}

int main(){
	long long int n,m,s[200005]={},type,res=0;
	cin>>n>>m;
	for(long long int i=1;i<=2*n;i++){
		kaijyou[i]=i*kaijyou[i-1];
		kaijyou[i]%=mod;
	}
    
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	type=GyakuLIS(n,s);
    //cout<<"TYPE>> "<<type<<endl;
	if(type>2){cout<<"0"<<endl;return 0;}
    
	if(type==1){
        //cout<<"TYPE1";
		for(int i=n-m;i<=m;i++){
			res+=combination(n,i);
			res%=mod;
		}		
		cout<<res<<endl;
		
	}else{
		long long int mode=0,count1=0,count2=0,memo,mymax=0;
		vector<pair<long long int,long long int> >vec;
		vec.push_back({0,0});
		for(int i=1;i<=n;i++){
            mymax=max(mymax,s[i]);
            //cout<<i<<" "<<mymax<<endl;
			if(mode==0){
				if(mymax==i){
					vec.push_back({1LL,0LL});
				}else{
					mode=1;
					count1=1;
				}
			}else if(mode==1){
				if(s[i]>s[i-1]){
					count1++;
				}else{

                    if(mymax==i){
                        
					    vec.push_back({count1,count2+1});
						//vec.push_back({1LL,0LL});
						mode=0;
                        count1=0;
                        count2=0;
					}else{
					mode=2;
					count2++;memo=s[i-1];
					}
                    
				}
			}else{
				if(mymax!=i&&memo>s[i]){
					count2++;
				}else{
					//vec.push_back({count1,count2});
					//count1=0;
					//count2=0;
					if(mymax==i){
                        
					    vec.push_back({count1,count2+1});
						//vec.push_back({1LL,0LL});
						mode=0;
                        count1=0;
                        count2=0;
					}else{
						count1++;
						mode=1;
					}
				}
			}

		}
        
		if(count1>0||count2>0){vec.push_back({count1,count2});}
		dp[0][0]=1;
		for(int i=1;i<vec.size();i++){
            
            //cout<<"DEBUG : "<<vec[i].first<<" : "<<vec[i].second<<endl;
			for(int j=0;j<=m;j++){
				if(j+vec[i].first<=m){dp[i][j+vec[i].first]+=dp[i-1][j];}
				if(j+vec[i].second<=m){dp[i][j+vec[i].second]+=dp[i-1][j];}
				dp[i][j+vec[i].first]%=mod;
				dp[i][j+vec[i].second]%=mod;
			}
		}
    //cout<<DEBUG<<endl;
        res=0;
		for(int i=n-m;i<=m;i++){
			res+=dp[vec.size()-1][i];
		}
        
		cout<<res%mod<<endl;
		
		//for(int i=1;i<vec.size();i++){
			//cout<<vec[i].first<<" "<<vec[i].second<<endl;
		//}
	}

}



Measured memory_bytes: 122580