#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
map<pair<int, int>, bool> pos;
int v[N];
bool p[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
  }
  for (int i = 1; i <= m; i++) {
    pair<int, int> aux;
    scanf("%d%d", &aux.first, &aux.second);
    pos[aux] = true;
  }
  int posnou = n;
  for (int i = n - 1; i >= 1; i--) {
    int j = i;
    while (p[j]) j++;
    while (j < posnou && pos[{v[i], v[j + 1]}]) {
      j++;
      while (p[j]) j++;
    }
    if (j >= posnou) {
      posnou--;
      p[i] = true;
    }
  }
  printf("%d", n - posnou);
  return 0;
}
