#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, m, gi, pz[300005];
int pe[300005], nr, cr[300005];
vector<int> v[300005];
map<int, int> mp[300005];
bool isg[300005];
set<int> s;
bool cmp(int a, int b) { return pz[a] < pz[b]; }
struct vct {
  int nr;
  int stop;
};
vct q[300005];
bool cmp2(vct a, vct b) { return a.stop < b.stop; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> pe[i], pz[pe[i]] = i;
  gi = pe[n];
  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    mp[a][b] = 1;
  }
  pz[n + 2] = n + 2;
  int qqqq = 0;
  for (int i = 1; i <= n; ++i) {
    sort(v[i].begin(), v[i].end(), cmp);
    bool st = 0;
    int stop = 0;
    int prev = pz[i];
    v[i].push_back(n + 2);
    for (int j = 0; j < v[i].size(); ++j)
      if (pz[v[i][j]] > pz[i]) {
        if (pz[v[i][j]] - 1 > prev) {
          stop = prev + 1;
          break;
        } else
          prev = pz[v[i][j]];
      }
    if (i != gi) q[++qqqq] = {i, stop};
  }
  sort(q + 1, q + qqqq + 1, cmp2);
  int aa = qqqq;
  for (; aa >= 1;) {
    if (q[aa].stop > n && mp[q[aa].nr][gi])
      s.insert(pz[q[aa].nr]), --aa;
    else if (q[aa].stop > n)
      --aa;
    else
      break;
  }
  int poz = n;
  int pppp = 0;
  while (!s.empty()) {
    ++pppp;
    set<int>::reverse_iterator it = s.rbegin();
    int nr = *it;
    --poz;
    s.erase(nr);
    for (; aa >= 1;) {
      if (q[aa].stop >= poz && mp[q[aa].nr].find(gi) != mp[q[aa].nr].end())
        s.insert(pz[q[aa].nr]), --aa;
      else if (q[aa].stop >= poz)
        --aa;
      else
        break;
    }
  }
  cout << n - poz;
  return 0;
}
