/*************************************************************
     File Name: F.cpp
     Created Time: Fri 18 May 2018 07:43:41 PM CST
 ************************************************************/

#include <iostream>
#include <vector>
using namespace std;

struct uf_tree {
  vector<int> parent;
  uf_tree(int s) : parent(s, -1) {}
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (parent[x] > parent[y]) swap(x, y);
    parent[x] += parent[y];
    parent[y] = x;
  }
  int find(int x) {
    return parent[x] < 0 ? x : parent[x] = find(parent[x]);
  }
  bool is_same(int x, int y) {
    return find(x) == find(y);
  }
};

int a[100000 + 10];
int main() {
  int n, m, x, y;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; ++i) cin >> a[i];
    uf_tree uf(n + 1);
    while (m--) {
      cin >> x >> y;
      uf.unite(a[x], a[y]);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
      if (uf.is_same(i, a[i]))
        ++ans;
    cout << ans << endl;
  }
}
