#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]);
  }
  int ind = a[n - 1];
  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 cnt = 0;
  int pos = n - 1;
  bool vis[300100] = {0};
  while (pos >= 1) {
    if (vis[a[pos - 1]]) break;
    if (s[a[pos]].find(a[pos - 1]) != s[a[pos]].end()) {
      a[pos - 1] = a[pos];
      cnt++;
      pos--;
    } else {
      vis[a[pos - 1]] = true;
      int j = pos - 1;
      while (j - 1 >= 0 && s[a[j]].find(a[j - 1]) != s[a[j]].end()) {
        swap(a[j], a[j - 1]);
        j--;
      }
    }
  }
  printf("%d\n", cnt);
}
