#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> order(n);
  for (int i = 0; i < n; i++) {
    cin >> order[i];
    order[i]--;
  }
  vector<list<int>> edges(n, list<int>());
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  set<int> toOvertake;
  toOvertake.insert(order[n - 1]);
  int ans = 0;
  for (int i = n - 2; i >= 0; i--) {
    int totalPass = 0;
    for (auto it = edges[order[i]].begin(); it != edges[order[i]].end(); it++)
      if (toOvertake.find(*it) != toOvertake.end()) totalPass++;
    if (totalPass < toOvertake.size())
      toOvertake.insert(order[i]);
    else
      ans++;
  }
  cout << ans << endl;
  return 0;
}
