Sunny is a teacher. Recently, he asked his students to tell him the class number of whom they have a crush on in class. Each student has exactly one crush (possibly themselves). Also, their crushes are unique, meaning no two students love the same student at the same time.

After knowing all the love relationships, Sunny creates a sequence $P$ of length $N$ to represent the relationships mathematically. For each $1 \le i \le N$, student $i$ has a crush on student $P_i$.

Sunny noticed that there are several "love cycles" formed among the class. A love cycle is a sequence of distinct class numbers $C_1, \dots, C_M$ where $P_{C_1}=C_2, P_{C_2}=C_3, \dots, P_{C_M}=C_1$.

For example, if $P=[2,4,5,1,3,6]$, then $[1,2,4],[3,5]$ and $[6]$ are love cycles.

Sunny is given the power to swap his students’ crushes. Sunny is interested in seeing long love cycles in his class, so he asks you to find the maximum length of a love cycle that can be formed after performing some swaps.

More specifically, Sunny can swap two students’ crushes, $P_i$ and $P_j$, for a cost of $|i-j|$. Find the maximum length of a love cycle in the class after performing several actions (possibly zero) with a total cost of at most $K$.

Input

The first line of input contains two integers $N$ and $K$. The second line of input contains $N$ integers, $P_1, P_2, \dots , P_N$.

Output

Output one integer: the length of the maximum length of love cycle after performing some actions with total cost of at most $K$.

Constraints

For all subtasks: $1 \le N \le 10^5, 0 \le K \le 2, P$ is a permutation of $\{1, 2, \cdots, N\}$
Subtask 1 (17%): $N \le 9$
Subtask 2 (5%): $P_i=i$
Subtask 3 (13%): $K \le 1$
Subtask 4 (27%): $N \le 1000$
Subtask 5 (38%): No additional constraints

Sample Test Cases

Input Output
6 0
2 4 5 1 3 6
3
The maximum length cycle is $[1,2,4]$ because you cannot perform any operations.
6 1
2 4 5 1 3 6
5
We could, for example, swap $P_3$ and $P_4$ to get $P=[2,4,1,5,3,6]$, with a cost of 1. In this case, the maximum length cycle is $[1,2,4,5,3]$.
1 2
1
1
9 2
7 5 1 6 2 9 4 8 3
9
Click to copy.

Scoring: Per Subtask
Authored by s17r28
Appeared in 2022 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆