H - Partitioned Subgraph

Languages: C++, Java, Python, Kotlin
Time & Memory limits: (details)

Input

Output

Sample test(s)

Input
4 4 1 2 2 3 2 4 3 4
Output
3
Input
2 0
Output
2

Hints