#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using ld = double;
using pld = pair<ld, ld>;
template <class T>
istream &operator>>(istream &in, vector<T> &a) {
  for (auto &i : a) in >> i;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> a) {
  for (auto &i : a) out << i << ' ';
  return out;
}
template <class T, class U>
istream &operator>>(istream &in, pair<T, U> &p) {
  in >> p.first >> p.second;
  return in;
}
template <class T, class U>
ostream &operator<<(ostream &out, pair<T, U> p) {
  out << p.first << " " << p.second << " ";
  return out;
}
inline void Start() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
ll n, m;
vector<ll> p, rev;
vector<set<ll>> g;
vector<ll> ans;
signed main() {
  Start();
  cin >> n >> m;
  p.resize(n);
  cin >> p;
  for (auto &i : p) --i;
  g.resize(n);
  vector<ll> fl;
  for (ll i = 0; i < m; ++i) {
    ll u, v;
    cin >> u >> v, --u, --v;
    g[u].emplace(v);
    if (v == p[n - 1]) fl.emplace_back(u);
  }
  rev.resize(n);
  for (ll i = 0; i < n; ++i) rev[p[i]] = i;
  sort((fl).rbegin(), (fl).rend(), [&](ll i, ll j) { return rev[i] < rev[j]; });
  ll j = 0, ans = 0;
  vector<bool> used(fl.size());
  for (ll i = n - 2; i >= 0 && j < fl.size(); --i) {
    if (fl[j] == p[i] && !used[j]) {
      ++ans;
      ++j;
    } else {
      for (ll lol = j; lol < fl.size(); ++lol) {
        if (!g[fl[lol]].count(p[i])) used[fl[lol]] = true;
      }
    }
  }
  cout << ans;
  return 0;
}
