#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<int> g[N];
int ans[N], og[N], m, n, sum;
bool fi(int i, int j) {
  int lo = -1, hi = g[i].size();
  while (lo < hi) {
    int mid = (lo + hi + 1) / 2;
    if (g[i][mid] < j) lo = mid;
    if (g[i][mid] > j) hi = mid - 1;
    if (g[i][mid] == j) return true;
  }
  return false;
}
bool solve(int i) {
  if (ans[i] != -1) {
    return ans[i];
  }
  for (int j = i + 1; j <= n - 1; j++) {
    if (!solve(j)) {
      if (!fi(i, j)) {
        return ans[i] = 0;
      }
    }
  }
  return ans[i] = 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    og[a] = i;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u = og[u], v = og[v];
    if (u > v) continue;
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    sort(g[i].begin(), g[i].end());
  }
  for (int i = 1; i <= n; i++) {
    ans[i] = -1;
  }
  solve(1);
  for (int i = 1; i <= n - 1; i++) {
    sum += ans[i];
  }
  printf("%d\n", sum);
  return 0;
}
