include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10000000];
vector<int> V[100005];
map<ll, ll> tp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
int l = 1;
int r = 0;
ll ans = 0;
while(l <= n)
{
while(r <= n && r - l + 1 - tp[a[l]] <= k)
{
r++;
a[r];
tp[a[r]]++;
}
ans = max(ans, tp[a[l]]);
while(l <= n && a[l] == a[l + 1])
{
tp[a[l]]--;
l++;
}
tp[a[l]]--;
l++;
}
cout << ans << "\n";
return 0;
}</int>