#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> par, pos;
int root(int v) { return par[v] < 0 ? v : (par[v] = root(par[v])); }
void merge(int x, int y) {
  if ((x = root(x)) == (y = root(y))) return;
  if (par[y] < par[x]) swap(x, y);
  par[x] += par[y];
  par[y] = x;
}
vector<vector<bool>> mat;
int main() {
  cin >> n >> m;
  pos.resize(n);
  mat.assign(n + 1, vector<bool>(n + 1, false));
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    pos[x] = i;
  }
  par.assign(n + 1, -1);
  vector<int> deg(n + 1);
  vector<bool> good(n + 1, false);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u = pos[u];
    v = pos[v];
    merge(u, v);
    deg[min(u, v)] += 1;
    if (u == n || v == n) good[u ^ v ^ n] = true;
  }
  int cnt = 0;
  for (int i = n - 1; i >= 1; i--) {
    if (root(i) != root(n)) break;
    if (good[i] && deg[i] == n - i) cnt += 1;
  }
  cout << cnt << endl;
}
