The input consists of about 50 test cases. The first line of each test case contains two integers, n and m, the number of beads of the necklace and the number of colors of beads Alice has (2 < n ≤ 100000, 1 ≤ m ≤ 100000). The second line contains n integers, the i-th of which, named pi, means that there is a string from the i-th bead to the pi-th bead (1 ≤ pi ≤ n and pi does not equal to i). The necklace is always valid and there is no duplicated string connecting the same pair of beads.