#import <Foundation/Foundation.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)

int main() {
	@autoreleasepool {
		NSMutableArray *A = [NSMutableArray array];
		int n;
		scanf("%d", &n);
		rep(i,n) [A addObject: [NSMutableSet set]];
		int ans=0;
		rep(i,n) {
			int a;
			scanf("%d",&a);
			a--;
			NSMutableSet *set = (NSMutableSet*)[A objectAtIndex:a];
			[set addObject:@(i)];
			set = (NSMutableSet*)[A objectAtIndex:i];
			if([set containsObject:@(a)]) ans++;
		}
		printf("%d\n",ans);
	}
}
