public class Skarbonka {

static int n;

static int max_n = 1000001;

static int []gdzie = new int[max_n];

static int []Numer = new int[max_n];

static int liczba;

public static void main(String[] args){

StreamTokenizer strTok = new StreamTokenizer(new BufferedReader(

new InputStreamReader(System.in)

)

);

System.out.println("Podaj liczbe skrzynek:");

try{

strTok.nextToken();

n = (int)strTok.nval;

System.out.println("Wpisz kolejno wartosci");

for(int i = 1; i <= n; i++){

strTok.nextToken();

gdzie[i] = (int)strTok.nval;

}

}catch(IOException e){

System.err.println("Input stream error");

return;

}

zlicz();

System.out.println(liczba);

}

static void zlicz(){

int i, j;

liczba = 0;

for(i = 1; i <=n; i++){

Numer[i] = 0;

j = i;

while(Numer[j] == 0){

Numer[j] = i;

j = gdzie[j];

if(Numer[j] == i){

liczba++;

}

}

}

}

}