#include <bits/stdc++.h>
using namespace std;
int n, m, nastya;
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;
}
int main() {
  cin >> n >> m;
  pos.resize(n);
  for (int i = 0; i < n; i++) cin >> pos[i];
  nastya = pos[n - 1];
  par.assign(n + 1, -1);
  int deg = 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (u == nastya || v == nastya) deg += 1;
    merge(u, v);
  }
  int cnt = 0;
  for (int i = n - 2; i >= 0; i--) {
    int x = pos[i];
    if (root(x) == root(nastya))
      cnt += 1;
    else
      break;
  }
  cout << min(cnt, deg) << endl;
}
