import collections
n, k = map(int, input().split())
array = list(map(int, input().split()))
count = collections.defaultdict(int)
right = 0
left = 0
result = 0
while right < n:
if count[array[right]] != k:
count[array[right]] += 1
right += 1
else:
count[array[left]] -= 1
left += 1
result = max(result, right - left)
print(result)