#include <bits/stdc++.h>
using namespace std;
vector<int> g[300050];
int p[300050];
bool vis[300050], np[300050], cut[300050];
int n, m, u, v;
int bfs(int u) {
  queue<int> q;
  while (!q.empty()) q.pop();
  memset(vis, false, sizeof(vis));
  q.push(u);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    vis[u] = true;
    for (auto x : g[u]) {
      if (np[x] && !cut[x]) {
        cut[x] = true;
        return x;
      }
      if (!vis[x]) q.push(x);
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  memset(vis, false, sizeof(vis));
  memset(np, false, sizeof(np));
  memset(cut, false, sizeof(cut));
  for (int i = 0; i <= n; i++) g[i].clear();
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    if (v == p[n - 1]) np[u] = true;
    g[v].push_back(u);
  }
  int c = 0, x, y = n, temp;
  while (1 && y > 1) {
    x = bfs(p[y - 1]);
    if (x) {
      temp = p[y - 1];
      p[y - 2] = p[y - 1];
      y--;
      c++;
    } else if ((x = bfs(p[y - 2]) != 0)) {
      c++;
    } else
      break;
  }
  printf("%d\n", c);
  return 0;
}
