#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> g;
vector<int> p(n);
vector<bool> used;
int main() {
  cin >> n >> m;
  p.resize(n + 1);
  map<int, int> ma;
  map<pair<int, int>, bool> used;
  for (int i = 1; i < n + 1; ++i) {
    cin >> p[i];
    ma[p[i]] = i;
  }
  set<int> hui;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    used[{x, y}] = true;
    if (y == p[n])
      ;
    hui.insert(ma[x]);
  }
  set<int>::iterator it = end(hui);
  int i = n;
  while (it != begin(hui)) {
    for (int t = i - 1; t > *it; ++t) {
      if (!used[{p[*it], p[t]}]) {
        break;
      }
    }
    i = *it;
    it = prev(it);
  }
  int res = 0;
  while (it != end(hui)) {
    res++;
    it = next(it);
  }
  cout << res;
  return 0;
}
