#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
struct Edge {
  int v, next;
} edge[N << 1];
int head[N], esize;
inline void addedge(int x, int y) {
  edge[++esize] = (Edge){y, head[x]};
  head[x] = esize;
}
bitset<N> bs1, bs2;
int n, m, a[N], ans;
bool ins(int x) {
  bs2.reset();
  bs2.set(x);
  bs2 &= bs1;
  bool res = bs2.count();
  bs2.reset();
  for (int i = head[x], vv; ~i; i = edge[i].next) {
    vv = edge[i].v;
    bs2.set(vv);
  }
  bs1 &= bs2;
  return res;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1, x, y; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    addedge(y, x);
  }
  ans = -1;
  bs1.set();
  for (int i = n; i >= 1; --i) {
    if (ins(a[i])) ++ans;
  }
  printf("%d", ans);
  return 0;
}
