#include <bits/stdc++.h>
using namespace std;
void io() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
}
signed main() {
  io();
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  vector<vector<int>> g(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<int> pos(n + 1);
  for (int i = 0; i < n; i++) {
    pos[v[i]] = i;
  }
  vector<int> can(n + 1, 0);
  vector<int> after(n + 1, 0);
  set<pair<int, int>> se;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    if (se.find({u, v}) == se.end()) {
      se.insert({u, v});
      if (pos[u] < pos[v]) after[u]++;
    }
  }
  int ans = 0;
  for (int i = n - 2; i > -1; i--) {
    int left = n - 1 - i;
    int cnt = ans;
    for (auto x : g[v[i]]) {
      if (can[x]) cnt--;
    }
    if (g[v[i]].size() + cnt >= left) ans++, can[v[i]] = 1;
  }
  cout << ans;
  return 0;
}
