#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5 + 10;
int ord[MAX_N];
int root[MAX_N];
bool cmp(const int u, const int v) { return ord[u] < ord[v]; }
int get(int u) {
  if (root[u] == u) return root[u] = u;
  return root[u] = get(root[u]);
}
void merge(int u, int v) {
  u = get(u);
  v = get(v);
  if (u == v) return;
  if (u > v) swap(u, v);
  root[u] = v;
}
int main() {
  for (int i = 0; i < MAX_N; i++) root[i] = i;
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> pos(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &pos[i]);
    pos[i]--;
    ord[pos[i]] = i;
  }
  vector<int> take;
  int s = pos.back();
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--, v--;
    merge(u, v);
    if (v == s) take.push_back(u);
  }
  int pib = n - 1;
  int ans = 0;
  sort(begin(take), end(take), cmp);
  while (not take.empty()) {
    bool ok = true;
    int to = ord[take.back()];
    take.pop_back();
    while (pib >= to) {
      ok &= (get(pos[pib]) == get(s));
      pib--;
    }
    if (ok)
      ans++;
    else
      break;
  }
  printf("%d\n", ans);
  return (0);
}
