#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 5010

/* Binary Indexed Tree(0-index) */

template <typename Type = int>
struct BIT{
  int bit_size;
  vector<Type> data;

  void init(int n){
    bit_size = n;
    data.assign(n+2, 0);
  }

  //add x to kth value
  void add(int k, Type x){
    k++;
    while(k <= bit_size){
      data[k] += x;
      if (data[k] >= mod) data[k] -= mod;
      k += k & (-k);
    }
  }

  //sum of [0,k)
  Type query(int k){
    ll rec = 0;
    while(k > 0){
      rec += data[k];
      k -= k & (-k);
    }
    return rec % mod;
  }

  //sum of [a, b)
  Type query(int a, int b){
    return query(b) - query(a);
  }
};

int s[SIZE];
BIT<int> bit[SIZE];
vector<pair<int,int>> history[SIZE];

int main(){
  int N, M;

  cin >> N >> M;

  s[0] = 0;
  for (int i=0; i<N; i++)
    cin >> s[i+1];


  for (int i=0; i<=N; i++) {
    bit[i].init(N+1);
  }

  bit[0].add(0, 1);
  history[0].push_back({0, 1});

  for (int i=0; i<N; i++) {
    vector<pair<int,int>> vec;

    for (int j=0; j<=i; j++) {
      int x = bit[j].query(s[i+1]);
      vec.push_back({i-j, x});

      if (s[i] > s[i+1]) {
        for (auto p : history[j]) {
          bit[j].add(p.first, mod-p.second);
        }
        history[j].clear();
      }
    }

    for (auto p : vec) {
      bit[p.first].add(s[i], p.second);
      history[p.first].push_back({s[i], p.second});
    }
  }

  ll ans = 0;
  for (int i=N-M; i<=M; i++) {
    ans += bit[i].query(N+1);
  }

  cout << ans % mod << endl;

  return 0;
}

