#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n + 4];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  set<int> s[n + 5];
  for (int i = 0; i < m; i++) {
    int u, t;
    scanf("%d %d", &u, &t);
    s[t].insert(u);
  }
  int ind = a[n - 1];
  int temp = -1;
  for (int i = 1; i < n - 1; i++) {
    if (s[ind].find(a[i]) == s[ind].end()) {
      int k = i;
      while (k - 1 >= 0 && a[k - 1] != temp &&
             s[a[k]].find(a[k - 1]) != s[a[k]].end()) {
        swap(a[k], a[k - 1]);
        k--;
      }
      temp = a[k];
    }
  }
  int k = n - 1;
  int cnt = 0;
  while (k - 1 >= 0 && s[a[k]].find(a[k - 1]) != s[a[k]].end()) {
    swap(a[k], a[k - 1]);
    cnt++;
    k--;
  }
  printf("%d\n", cnt);
}
