#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  vector<int> p;
  vector<int> x;
  vector<int> y;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    p.push_back(a);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    x.push_back(a);
    y.push_back(b);
  }
  vector<unordered_set<int>> groups;
  for (int i = 0; i < n; i++) {
    unordered_set<int> g;
    g.insert(i + 1);
    groups.push_back(g);
  }
  for (int i = 0; i < m; i++) {
    int v1 = x[i];
    int v2 = y[i];
    int xi = -1;
    int yi = -1;
    for (int j = 0; j < (int)groups.size(); j++) {
      unordered_set<int>& group = groups[j];
      if (group.count(v1) >= 1) {
        xi = j;
      }
      if (group.count(v2) >= 1) {
        yi = j;
      }
    }
    if (xi != yi) {
      unordered_set<int>& source = groups[yi];
      for (int v : source) {
        groups[xi].insert(v);
      }
      groups.erase(groups.begin() + yi);
    }
  }
  int result = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (int)groups.size(); j++) {
      unordered_set<int>& group = groups[j];
      if (group.count(i) >= 1) {
        for (int idx : group) {
          if (p[idx - 1] == i) {
            result++;
            break;
          }
        }
        break;
      }
    }
  }
  cout << result << endl;
  return 0;
}
