#include<bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = 0;(i) < (n);i++)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) b.begin(),v.end()
#define SHOW1d(v, n) {REP(WW,n)cerr<<v[WW]<<" ";cerr<<endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr<<v[W_][H_]<<" ";cerr<<endl;}cerr<<endl;}
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

struct UF
{
  vector<int> par;
  vector<int>sz;
  vector<int>rank;
  UF(int n):par(n),sz(n),rank(n){
    for(int i=0;i<n;i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  int find(int x){
    if(par[x]==x)return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x = find(x);y = find(y);
    if(x == y)return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(int x,int y){return find(x) == find(y);}
  int size(int n){return sz[find(n)];}
};

vector<vector<int>> g(5555);
bool used[5555];
int color[5555];
int color_a, color_b;
int dp[5555][5555];
bool ng_flag;

void mod_add(int &a, int b){
  a += b;
  a %= MOD;
}

void dfs(int a){
  //cout << "dfs in " << a << endl;
  used[a] = true;
  if(color[a] == 1)color_a++;
  else color_b++;

  REP(i, g[a].size()){
    //cout << "dfs " << a << " " << g[a][i] << endl;
    int aite = g[a][i];
    if(color[aite] * color[a] == 1){
      //cout << "!! " << aite << " " << a << endl;
      ng_flag = true;
      continue;
    }
    if(used[aite])continue;
    if(color[aite] == 0){
      color[aite] = -color[a];
    }
    dfs(aite);
  }
}

int main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

  ll n, m;cin >> n >> m;
  vector<ll> v(n);
  REP(i, n)cin>>v[i];

  for(int i = n-1;i >= 0;i--){
    for(int j = i-1;j >= 0;j--){
      if(v[i] < v[j]){
        //cout << "! " << v[i] << " " << v[j] << endl;
        g[i].PB(j);
        g[j].PB(i);
      }
    }
  }
  vector<P> seica;

  REP(i, n){
    //cout << i << endl;
    if(used[i])continue;
    color[i] = 1;
    color_a = 0;
    color_b = 0;
    dfs(i);
    if(ng_flag){
      cout << 0 << endl;
      return 0;
    }
    seica.EB(color_a, color_b);
  }

/*
  SHOW1d(color, n);
  REP(i, seica.size()){
    cout << "(" << seica[i].FI << " " << seica[i].SE << ")";
  }cout << endl;
*/
  dp[0][0] = 1;
  int sum = 0;
  REP(i, seica.size()){
    REP(j, 5555){
      if(dp[i][j] == 0)continue;
      ll a_high = j;
      ll b_high = sum - j;
      //cout << i << " " << a_high << " " << b_high << endl;
      if(a_high + seica[i].FI <= m && b_high + seica[i].SE <= m){
        //cout << "A" << endl;
        mod_add(dp[i+1][a_high + seica[i].FI], dp[i][j]);
      }
      if(a_high + seica[i].SE <= m && b_high + seica[i].FI <= m){
        //cout << "B" << endl;
        mod_add(dp[i+1][a_high + seica[i].SE], dp[i][j]);
      }
    }
    sum += seica[i].FI;
    sum += seica[i].SE;
  }

  //SHOW2d(dp, seica.size() + 1, 10);

  int ans = 0;
  REP(i, 5555)mod_add(ans, dp[seica.size()][i]);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 47808