#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

//using lll=boost::multiprecision::cpp_int;
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;


void solve()
{	
	int n,m;
	cin>>n>>m;
	vector<int>a(n);
	rep(i,n)cin>>a[i];

	vector<int>cur(n+1,-1),nx(n+1,-1);
	int ans=n;
	rep(i,n){
		int pre=cur[a[i]];
		cur[a[i]]=i;
		nx[a[i]]=i+(m-1);
		if(i-pre>m){
			chmin(ans,a[i]);
		}
	}
	rep(i,n+1){
		if(nx[i]<n-1){
			chmin(ans,i);
		}
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,b) for(int i = a; i<b ; i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define pb push_back
#define M 1000000007
int mod(int x){
return ((x%M + M)%M);
}
int add(int a,int b){
return mod(mod(a)+mod(b));
}
int mul(int a,int b){
return mod(mod(a)*mod(b));
}
// ****************************************************************************
int a[3002];
int n;
int dp[2][3002][3002];
int store[3002][3002];
// take 1 based indexing
void fun(){
   fo(j,1,n+1){
    //    j is the sequnce number
    int sum = 0;
    map<int,int>m;
    m[0]=0;
    fo(i,1,n+1){
        sum+=a[i];
        int curr = sum%j;
        if(m.find(curr)!=m.end()){
            store[m[curr]+1][j]=i;
        }
        m[curr]=i;
    }
   }
}
int rec(int f,int j,int i){
    if(i==n+1)
    return 1ll;
    if(dp[f][j][i]!=-1)
    return dp[f][j][i];
    int ans = 0;
    if(!f){
        // now i have to start jth sequnce from me
        // find the next pointer
        int next = store[i][j];
        if(!next)
        return 0;
        ans = mod(rec(1,j,next + 1));
    }
    else{
        // now i have got a jth sequnce
        // now start a new one from me
        ans = mod(rec(0,j+1,i));
        int next = store[i][j];
        if(next)
        ans=add(ans,rec(1,j,next+1));
    }
    return dp[f][j][i]=ans;
}
void solve(){
    cin>>n;
    fo(i,1,n+1)
    cin>>a[i];
    fun();
    // fo(i,1,n+1){
    //     fo(j,2,n+1)
    //     cout<<store[i][j]<<" ";
    //     cout<<"\n";
    // }
    memset(dp,-1,sizeof dp);
    cout<<rec(0,1,1);
}
signed main()
{
FIO
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
}