#include <bits/stdc++.h>
using namespace std;
const int sz = 3e5 + 5;
int n, m, q[sz], pos[sz];
int fr[sz] = {0}, sfr[sz] = {0};
map<pair<int, int>, bool> ch;
vector<pair<int, int> > myf, sw;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> q[i];
    pos[q[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    ch[{u, v}] = 1;
    if (v == q[n - 1]) myf.push_back({pos[u], u});
    sw.push_back({u, v});
  }
  for (int i = 0; i < m; i++) {
    int u = sw[i].first, v = sw[i].second;
    if (pos[v] > pos[u] && ch.find({v, q[n - 1]}) != ch.end())
      sfr[u] += 1;
    else if (pos[v] > pos[u])
      fr[u] += 1;
  }
  sort(myf.begin(), myf.end(), greater<pair<int, int> >());
  int steps = 0;
  for (int i = 0; i < myf.size(); i++) {
    int he = myf[i].second;
    int hpos = myf[i].first, mypos = n - 1 - steps;
    int a = fr[he], b = sfr[he];
    b = max(b - steps, 0);
    if (mypos - hpos == a + b) steps++;
  }
  cout << steps << endl;
  return 0;
}
