P4670 [CF802B] Heidi and Library (medium)
提高-
题目描述

Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.

Input

Same as the easy version, but the limits have changed: 1 ≤ n, k ≤ 400 000.

Output

Same as the easy version.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 100 1 2 2 1
样例输出
2