#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MAXN = (int)3e5 + 13;
set<int> g[MAXN], g2[MAXN];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> p(n), pos(n);
  vector<pii> reb(m);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  int nas = p.back();
  for (int i = 0; i < n; i++) {
    pos[p[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    cin >> reb[i].first >> reb[i].second;
    reb[i].first--, reb[i].second--;
    g[reb[i].first].insert(reb[i].second);
    g2[reb[i].second].insert(reb[i].first);
  }
  set<pii> nst;
  for (auto i : g2[nas]) {
    nst.insert({pos[i], i});
  }
  for (auto ps : nst) {
    int ci = pos[ps.second], curp = ps.second;
    while (ci < n - 1 && g[curp].find(p[ci + 1]) != g[curp].end()) {
      ++ci;
      swap(p[ci], p[ci - 1]);
      pos[curp] = ci;
      pos[p[ci - 1]] = ci - 1;
    }
  }
  cout << n - 1 - pos[nas] << "\n";
  return 0;
}
