#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MP make_pair
typedef long long ll;
#define mod 1000000007
ll comb[5001][5001];

ll dp[5001][2],dp2[5001][2];
ll ss[5002];

int main(){
    rep(i,5001){
        comb[i][0] = 1;
        comb[i][i] = 1;
    }
    for(int i=1;i<=5000;i++){
        for(int j=1;j<i;j++){
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
            comb[i][j] %= mod;
        }
    }
    int n,m;
    cin >> n >> m;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    vector<int>x,y;
    vector<int>F,G;
    vector<int>c;
    for(int i=1;i<n;i++){
        if(a[i]<a[i-1]){
            c.push_back(i);
            F.push_back(a[i-1]);
            G.push_back(a[i]);
        }
    }
    if(c.size()==0){
        ll sm = 0;
        for(int i= n-m;i<=m;i++){
            sm += comb[n][i];
            sm %= mod;
        }
        cout << sm << endl;
    }else{
        int s = 0;
        bool flag = 0;
        rep(i,c.size()){
            int id = c[i];
            int tar = a[id];
            int xx = 0;
            for(int j=s;j<=id-1;j++){
                if(a[j]>=tar){
                    xx++;
                }
            }
            x.push_back(xx);
            int yy = 0;
            int sss = a[id-1];
            int ppp = n;
            if(i!=c.size()-1){
                ppp = c[i+1];
            }
            for(int j=id;j<ppp;j++){
                if(a[j] < sss){
                    yy++;
                }
            }
            y.push_back(yy);
            //cerr << c[i] << " " << x[i] << " " << y[i] << endl;
            if(i!=0&&c[i]-c[i-1]<x[i]+y[i-1]){
                flag = true;
                // cerr << c[i]-c[i-1] << " " << x[i] + y[i-1] << endl;
                // cerr << c[i-1] << " "<< c[i] << endl;
                // cerr << x[i] << " " << y[i-1] << endl;
            }
            s = id;
        }
        if(flag){
            cout << 0 << endl;
            return 0;
        }
        ll p = 0;
        rep(i,c.size()){
            p += x[i] + y[i];
            //cerr << x[i] << " " << y[i] << endl;
        }
        p = n-p;
        dp[x[0]][0] = 1;
        dp[y[0]][1] = 1;
        rep(k,c.size()){
            if(k==0)continue;
            rep(i,5001){
                dp2[i][0] = 0;
                dp2[i][1] = 0;
            }
            for(int i=5000;i>=0;i--){
                if(i-x[k]>=0){
                    dp2[i][0] += dp[i-x[k]][0];
                    dp2[i][0] %= mod;
                    if(F[k-1]<G[k]){
                        dp2[i][0] += dp[i-x[k]][1];
                        dp2[i][0] %= mod;
                    
                    }
                }
                if(i-y[k]>=0){
                    dp2[i][1] += dp[i-y[k]][1];
                    dp2[i][1] %= mod;
                    if(F[k-1]<G[k]){
                        
                        dp2[i][1] += dp[i-y[k]][0];
                        dp2[i][1] %= mod;
                    }
                }
            }
            rep(i,5001){
                dp[i][0] = dp2[i][0];
                dp[i][1] = dp2[i][1];
            }
        }
        
        //cerr << p << endl;
        // rep(i,n+1){
        //     cerr << dp[i] << " ";
        // }
        // cerr << endl;
        ll res = 0;
        rep(i,n+2){
            if(i!=0){
                ss[i] = ss[i-1] + comb[p][i-1];
                ss[i] %= mod;
            }
        }
        rep(i,n+1){
            if(i>m)continue;
            int l = max(0,n-m-i);
            ll r = min(p+1,(ll)m-i+1);
            res += (dp[i][0]+dp[i][1])%mod*((mod+ss[r]-ss[l])%mod);
            res %= mod;
            //cerr << l << " " << r << " " << dp[i][0] << " " << dp[i][1] << " " << ss[l] << " " << ss[r] << endl;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 120068