#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = 4007;
const int mod = int(1e9)+7;
int add(int x , int y){
x += y;
if (x >= mod) x -= mod;
return x;
}
void self_add(int &x , int y){
x = add(x , y);
}
int mul(int x , int y){
return (1ll * x * y) % mod;
}
int n , m , a[maxN] , dp[maxN][maxN];
bool mark[maxN][maxN];
namespace sub1{
bool check(){
return (n <= 100 && m <= 400);
}
void solve(){
for (int i = 1 ; i <= n ; i++){
int cur = INT_MIN;
for (int j = i ; j <= n ; j++){
cur = max(cur , a[j]);
if (i > 1 && j < n){
mark[i - 1][j + 1] = (cur > max(a[i - 1] , a[j + 1]));
}
}
}
for (int i = 1 ; i <= n ; i++){
dp[i][a[i]] = 1;
for (int t = a[i] ; t <= m ; t++){
for (int j = 1 ; j < i ; j++){
if (mark[j][i] == 1) self_add(dp[i][t] , dp[j][t - a[i]]);
}
}
}
int ans = 1;
for (int i = 1 ; i <= n ; i++){
for (int t = 1 ; t <= m ; t++){
self_add(ans , dp[i][t]);
}
}
cout << ans << "\n";
}
}
void solve(){
cin >> n >> m;
for (int i = 1 ; i <= n ; i++) cin >> a[i];
if (sub1::check()) return sub1::solve();
}
#define name "K"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYmVnaW4oKSk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCAsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxsb25nIGxvbmcgLCBpbnQ+IGxsaTsKCmNvbnN0IGludCBtYXhOID0gNDAwNzsKY29uc3QgaW50IG1vZCA9IGludCgxZTkpKzc7CgppbnQgYWRkKGludCB4ICwgaW50IHkpewogICAgeCArPSB5OwogICAgaWYgKHggPj0gbW9kKSB4IC09IG1vZDsKICAgIHJldHVybiB4Owp9Cgp2b2lkIHNlbGZfYWRkKGludCAmeCAsIGludCB5KXsKICAgIHggPSBhZGQoeCAsIHkpOwp9CgppbnQgbXVsKGludCB4ICwgaW50IHkpewogICAgcmV0dXJuICgxbGwgKiB4ICogeSkgJSBtb2Q7Cn0KCmludCBuICwgbSAsIGFbbWF4Tl0gLCBkcFttYXhOXVttYXhOXTsKYm9vbCBtYXJrW21heE5dW21heE5dOwoKbmFtZXNwYWNlIHN1YjF7CiAgICBib29sIGNoZWNrKCl7CiAgICAgICAgcmV0dXJuIChuIDw9IDEwMCAmJiBtIDw9IDQwMCk7CiAgICB9CgogICAgdm9pZCBzb2x2ZSgpewogICAgICAgIGZvciAoaW50IGkgPSAxIDsgaSA8PSBuIDsgaSsrKXsKICAgICAgICAgICAgaW50IGN1ciA9IElOVF9NSU47CiAgICAgICAgICAgIGZvciAoaW50IGogPSBpIDsgaiA8PSBuIDsgaisrKXsKICAgICAgICAgICAgICAgIGN1ciA9IG1heChjdXIgLCBhW2pdKTsKICAgICAgICAgICAgICAgIGlmIChpID4gMSAmJiBqIDwgbil7CiAgICAgICAgICAgICAgICAgICAgbWFya1tpIC0gMV1baiArIDFdID0gKGN1ciA+IG1heChhW2kgLSAxXSAsIGFbaiArIDFdKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgICAgICBkcFtpXVthW2ldXSA9IDE7CiAgICAgICAgICAgIGZvciAoaW50IHQgPSBhW2ldIDsgdCA8PSBtIDsgdCsrKXsKICAgICAgICAgICAgICAgIGZvciAoaW50IGogPSAxIDsgaiA8IGkgOyBqKyspewogICAgICAgICAgICAgICAgICAgIGlmIChtYXJrW2pdW2ldID09IDEpIHNlbGZfYWRkKGRwW2ldW3RdICwgZHBbal1bdCAtIGFbaV1dKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbnQgYW5zID0gMTsKICAgICAgICBmb3IgKGludCBpID0gMSA7IGkgPD0gbiA7IGkrKyl7CiAgICAgICAgICAgIGZvciAoaW50IHQgPSAxIDsgdCA8PSBtIDsgdCsrKXsKICAgICAgICAgICAgICAgIHNlbGZfYWRkKGFucyAsIGRwW2ldW3RdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwogICAgfQp9Cgp2b2lkIHNvbHZlKCl7CiAgICBjaW4gPj4gbiA+PiBtOwogICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspIGNpbiA+PiBhW2ldOwogICAgaWYgKHN1YjE6OmNoZWNrKCkpIHJldHVybiBzdWIxOjpzb2x2ZSgpOwp9CgojZGVmaW5lIG5hbWUgIksiCgppbnQgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiAgICBpZiAoZm9wZW4obmFtZSIuSU5QIiAsICJyIikpewogICAgICAgIGZyZW9wZW4obmFtZSIuSU5QIiAsICJyIiAsIHN0ZGluKTsKICAgICAgICBmcmVvcGVuKG5hbWUiLk9VVCIgLCAidyIgLCBzdGRvdXQpOwogICAgfQogICAgaW50IHQgPSAxOyAvL2NpbiA+PiB0OwogICAgd2hpbGUgKHQtLSkgc29sdmUoKTsKICAgIHJldHVybiAwOwp9Cgo=