This page is still under construction.

Parts of this page are still being built. What you see may change.

The Club Trip

Time limit1sMemory limit256 MB

Summary
Each of n classmates rides only if one named classmate also rides; fill up to k bus seats with the largest group that respects every such condition.
Level

Medium7 of 10

Topics
Graph, Dynamic programming, Tree
Solved
No attempts yet

Problem

Namgyu chartered a bus so that he could go on a club trip with his classmates. The department office got the seat count wrong, so the bus cannot carry everyone. Once the classmates heard about it, they started saying things like this.

Jaehyeok: If Dongwoo does not go, I am not going either.
Dongwoo: If Sejong does not go, I will not go.

Seats are limited, and every classmate refuses to go unless one particular other person goes, so Namgyu is stuck. He bought far too much to drink, so he has to bring as many people as he can.

Given the person each classmate named, find the largest number of people that can ride the bus without breaking anyone's condition.

Input

The first line contains the number of people nn and the number of people the bus can carry kk. (1≤k≤n≤10001 \le k \le n \le 1000)

The second line contains the integers x1,x2,…,xnx_1, x_2, \dots, x_n in order. (1≤xi≤n1 \le x_i \le n) xix_i means that if person xix_i does not ride the bus, person ii does not ride it either.

Output

Print, on one line, the largest number of people that can ride the bus without breaking anyone's condition. Print 0 if nobody can ride.

Examples3

  1. Example 1

    Input
    4 4
    1 2 3 4
    
    Expected output
    4
    
  2. Example 2

    Input
    12 3
    2 3 4 5 6 7 4 7 8 8 12 12
    
    Expected output
    2
    
  3. Example 3

    Input
    5 4
    2 3 1 5 4
    
    Expected output
    3