#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long INF64 = 1e18;
const int N = 1e5 + 5;
vector<int> adjList[3 * N];
long long arr[3 * N];
bitset<3 * N> cur, now;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", arr + i);
  for (int i = 0; i < m; i++) {
    long long a, b;
    scanf("%lld %lld", &a, &b);
    adjList[a].push_back(b);
  }
  cur[arr[n]] = 1;
  int ans = 0;
  for (int i = n - 1; i > 0; i--) {
    for (auto it : adjList[arr[i]]) {
      now[it] = 1;
    }
    if ((now | cur) == now) {
      ans++;
    } else
      cur |= now;
    for (auto it : adjList[arr[i]]) {
      now[it] = 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}
