#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int pos[N], a[N];
set<int> t[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int &x = a[i];
    cin >> x;
    pos[x] = i;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    t[u].insert(pos[v]);
  }
  int res = 0;
  for (int i = 1; i <= n - 1; i++) {
    bool ok = 1;
    for (int j = pos[i] + 1; j <= n; j++) {
      set<int>::iterator it = t[a[i]].find(j);
      if (it == t[a[i]].end()) {
        ok = 0;
        break;
      }
    }
    if (ok) res++;
  }
  cout << res;
  return 0;
}
