#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
int a[500001];
int L[500001];
const int MOD = 1e9 + 7;
ll mult(ll a, ll b)
{
ll ans = (a*b)%MOD;
if(ans<0) ans+=MOD;
return ans;
}
ll add(ll a, ll b)
{
a+=b;
while(a>=MOD) a-=MOD;
while(a<0) a+=MOD;
return a;
}
ll dp[500001];
const int INF = int(1e7);
int cnt[500005];
int run;
int n,k;
void add(int x)
{
if(cnt[x]==0&&x<=k)
{
run++;
}
cnt[x]++;
}
void del(int x)
{
if(cnt[x]==1&&x<=k)
{
run--;
}
cnt[x]--;
}
ll sum[500001];
ll S(int l, int r)
{
if(l>r) return 0;
if(l<0) return add(sum[r],1);
else if(l==0) return sum[r];
else return add(sum[r],MOD-sum[l-1]);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>a[i];
a[i]=min(a[i],500001);
}
L[0]=0;
if(k==0&&a[0]==0) L[0]=INF;
int ptr=0;
run=0;
if(L[0]==0)
{
add(a[0]);
}
else
{
ptr=1;
}
for(int i=1;i<n;i++)
{
add(a[i]);
while(run>=k+1&&ptr<i)
{
del(a[ptr]);
ptr++;
}
if(ptr==i&&run>=k+1)
{
del(a[i]);
ptr=i+1;
L[i]=INF;
}
else
{
L[i]=ptr;
}
}
if(L[0]==0) dp[0]=1;
else dp[0]=0;
sum[0]=dp[0];
for(int i=1;i<n;i++)
{
dp[i]=S(L[i]-1,i-1);
sum[i]=add(sum[i-1],dp[i]);
}
cout<<dp[n-1]<<'\n';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