#include<bits/stdc++.h>
#define MAXN 301010
using namespace std;

int idx[MAXN];
int par[MAXN];

int rep(int x) {
	if(x == par[x]) return x;
	return par[x] = rep(par[x]);
}

void Union(int x , int y) {
	int T , X = rep(x);
	int Y = rep(y);
	if(X < Y) T = X , X = Y , Y = T;
	if(X != Y) par[X] = Y;
}

int main()
{
	int N , K , x , y;
	cin >> N >> K;
	int arr[N + 1] , U[K + 1];
	for(int i = 1 ; i <= N ; i++) par[i] = i;
	for(int i = 1 ; i <= N ; i++) cin >> arr[i] , idx[arr[i]] = i;
	for(int i = 0 ; i < K ; i++) cin >> x >> y , Union(arr[x] , arr[y]);
	for(int i = 1 ; i <= N ; i++) {
		int x = rep(i) , y = rep(arr[i]);
		if(x == y) {
			arr[ idx[ i ] ] = arr[i];
			idx[ arr[i] ] = idx[i];
			arr[i] = i;

		}
	}
	int cnt = 0;
	for(int i = 1 ; i <= N ; i++) if(i == arr[i]) cnt++;
	cout << cnt << endl;
}
