#include <bits/stdc++.h>
using namespace std;
int a[300005];
int num[300005];
vector<int> g[300005];
bool b[300005];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  int x, y;
  while (m--) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[a[i]].size(); j++) {
      if (!b[g[a[i]][j]]) num[i]++;
    }
    b[a[i]] = true;
  }
  int now = n;
  for (int i = n - 1; i >= 1; i--)
    if (num[i] + i == n) now--;
  cout << n - now << endl;
  return 0;
}
