n = int(raw_input())
h = {}
for i,a in enumerate(map(int, raw_input())):
	i += 1
	if a != i:
		h[a] = i

def get(u, parent):
	if parent[u] != u:
		parent[u] = get(parent[u], parent)
	return parent[u]

parent = {u:u for u in h}
sizes = {u:1 for u in h}
for u in h:
	v = h[u]
	pu,pv = get(u, parent), get(v, parent)
	if pu != pv:
		parent[pv] = pu
		sizes[pu] += sizes[pv]
print sum([sizes[u]-1 for u in parent if parent[u] == u] or [0])
