#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 4e3 + 5;
const int modu = 1e9 + 7;

inline void add(ll &x,ll y){x = (x + y) % modu;}

ll dp[maxn][maxn],a[maxn],f[maxn][maxn],predq[maxn][maxn];

void absorb_f(int p,int nxt,int m){
	for (int i = 0 ; i <= m ; i++){
	  add(f[p][i],f[nxt][i]);
      
      if (a[nxt] < a[p])
        add(f[p][i],dp[nxt][i]);
	}
}

void get_dp(int p,int lst,int m){
	for (int i = a[p] ; i <= m ; i++)
	  add(dp[p][i],predq[lst][i - a[p]]);
}

void get_predq(int p,int lst,int m){
	for (int i = 0 ; i <= m ; i++)
	  predq[p][i] = ((ll)predq[lst][i] + (ll)f[p][i]) % modu;
}

void perform_dynamic_programming(int n,int m){
	deque <int> dq,tdq;
	
	for (int i = 1 ; i <= n ; i++){
		//a[i] cannot be chosen, as a[i] > -> seen together
		while (dq.size() && a[i] > a[dq.back()]){
			absorb_f(i,dq.back(),m);
			dq.pop_back();
		}
		while (tdq.size() && a[i] >= a[tdq.back()]) tdq.pop_back();
		
		//self case
		dp[i][a[i]]++;
		
		if (tdq.size())
		  get_dp(i,tdq.back(),m);
		
		if (dq.size())
			get_predq(i,dq.back(),m);
		else 
		    get_predq(i,0,m);
		
		
		dq.push_back(i);
		tdq.push_back(i);
	}
}

int solve(int n,int m){
	ll res = 0;
	
	perform_dynamic_programming(n,m);
	
	for (int i = 1 ; i <= n ; i++){
		for (int j = 0 ; j <= m ; j++)
		  res = (res + dp[i][j]) % modu;
	}
	res++;
	if (res < 0) res += modu;
	return res;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	int n,m;
	cin >> n >> m;
	for (int i = 1 ; i <= n ; i++) cin >> a[i];
	
	cout << solve(n,m);

	return 0;
}
