Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

B. Heidi and Library (medium)

time limit per test

10 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputWhereas 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.

Examples

Input

4 100

1 2 2 1

Output

2

Input

4 1

1 2 2 1

Output

3

Input

4 2

1 2 3 1

Output

3

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/24/2018 09:15:33 (d1).

Desktop version, switch to mobile version.

User lists

Name |
---|