#include <bits/stdc++.h>
using namespace std;
int const maxn = 400000;
int p[maxn];
bool is_good[maxn];
int main() {
  int n, m, s;
  cin >> n >> m;
  vector<set<int>> adj(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    p[i]--;
  }
  s = p[n - 1];
  int u, v;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    --u;
    --v;
    adj[v].insert(u);
    if (v == s) is_good[u] = true;
  }
  set<int> good;
  for (int i = 0; i < n; ++i)
    if (is_good[i]) good.insert(i);
  int ans = 0;
  for (int i = n - 2; i >= 0; --i) {
    if (is_good[p[i]] && good.find(p[i]) != end(good)) {
      ++ans;
    }
    set<int> new_good;
    set_intersection(begin(adj[p[i]]), end(adj[p[i]]), begin(good), end(good),
                     inserter(new_good, begin(new_good)));
    good = new_good;
  }
  cout << ans << endl;
  return 0;
}
