import java.util.*;
public class test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Deque deque = new ArrayDeque<>();
Set set = new HashSet<Integer>();
int max = 0;
int n = in.nextInt();
int m = in.nextInt();
for (int i = 0; i < n; i++) {
int num = in.nextInt();
deque.add(num); // 민 뒤에 데이터 삼입
set.add(num);
if(deque.size() == m) {
max = Math.max(max, set.size()); // 두 인자 중 큰값
int poll = (int)(deque.poll()); // 맨 앞에서 하나 뽑아서 리턴, 빈 경우 null
if (!deque.contains(poll)) {
set.remove(poll);
}
}
}
System.out.println(max);
}
}