import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
import std.container.rbtree;
// foreach, foreach_reverse, writeln

class UnionFind {
	int[] data;
	this(int n) {
		data = new int[n];
		data[] = -1;
	}
	int find(int v) {
		if (data[v] < 0) return v;
		return data[v] = find(data[v]);
	}
	bool join(int u, int v) {
		u = find(u);
		v = find(v);
		if (u == v) return false;
		if (data[u] > data[v]) swap(u,v);
		data[u] += data[v];
		data[v] = u;
		return true;
	}
}

alias set = RedBlackTree!int;

void main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int[] p = new int[n];
	foreach (i; 0..n) scanf("%d", &p[i]);
	auto uf = new UnionFind(n);
	foreach (i; 0..m) {
		int x, y;
		scanf("%d%d", &x, &y);
		uf.join(x-1, y-1);
	}
	set[] s = new set[n];
	foreach (i; 0..n) s[i] = new set();
	foreach (i; 0..n) {
		int g = uf.find(i);
		s[g].insert(i);
	}
	int ans = 0;
	foreach (i; 0..n) {
		int g = uf.find(i);
		ans += s[g].equalRange(p[i]-1).empty?0:1;
	}
	writeln(ans);
}