#include <bits/stdc++.h>
using namespace std;
int movex[4] = {-1, 0, 1, 0};
int movey[4] = {0, 1, 0, -1};
int movex1[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int movey1[8] = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> adj[300005];
int a[300005], mark[300005];
int main() {
  int n, m, i, j, u, v, ans, cnt;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%d", &a[i + 1]);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    adj[v].push_back(u);
  }
  ans = cnt = 0;
  for (i = n - 1; i >= 1; i--) {
    if (mark[a[i]] == cnt && i != n) {
      ans++;
      continue;
    }
    for (auto x : adj[i]) mark[x]++;
    cnt++;
  }
  printf("%d\n", ans);
  return 0;
}
