#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> till(n + 1, 0);
  vector<long long> pos(n + 1, 0);
  vector<long long> p(n + 1, 0);
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    cin >> p[i];
    pos[p[i]] = i;
  }
  set<long long> col[n + 1];
  for (long long i = (long long)(1); i <= (long long)(m); i++) {
    long long u, v;
    cin >> u >> v;
    col[pos[u]].insert(pos[v]);
  }
  long long ans = 0;
  set<long long> bag, chosen;
  bag.insert(n);
  for (long long i = (long long)(n - 1); i >= (long long)(1); i--) {
    long long left = n - i;
    if (col[i].size() + chosen.size() < left) {
      continue;
    }
    long long con = 0;
    for (long long x : chosen) {
      if (col[i].count(x)) {
        con++;
      }
    }
    if (col[i].size() + chosen.size() - con == left) {
      chosen.insert(i);
    }
  }
  cout << chosen.size();
}
