#include <bits/stdc++.h>
using namespace std;
bool check(int a, int b, set<int> *s) {
  if (s[a].count(b) != 0)
    return true;
  else
    return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  int *arr = new int[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  set<int> s[n + 1];
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    s[b].insert(a);
  }
  int ans = 0;
  int p = arr[n - 1];
  vector<int> c(1);
  c[0] = p;
  int k = 1;
  for (int i = n - 2; i >= 0; i--) {
    k = 1;
    for (int z = 0; z < c.size(); z++) {
      k = k && check(c[z], arr[i], s);
    }
    if (k) {
      ans++;
    } else {
      c.push_back(arr[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
