#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5;
vector<int> g[MAXN];
bool used[MAXN];
int mxg[MAXN];
void dfs(int x) {
  used[x] = 1;
  mxg[x] = x;
  vector<pair<int, int> > gg;
  for (int i = 0; i < g[x].size(); i++) {
    int to = g[x][i];
    if (!used[to]) {
      dfs(to);
    }
    gg.push_back({mxg[to], to});
  }
  sort(gg.begin(), gg.end());
  for (int i = 0; i < gg.size(); i++)
    if (gg[i].second <= mxg[x] + 1) ++mxg[x];
}
int main() {
  memset(used, 0, MAXN * sizeof(bool));
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    int cx;
    cin >> cx;
    p[cx - 1] = i;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[p[u - 1]].push_back(p[v - 1]);
  }
  vector<int> dfw;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      int to = g[i][j];
      if (to == n - 1) {
        dfs(i);
        dfw.push_back(mxg[i]);
        break;
      }
    }
  }
  sort(dfw.begin(), dfw.end());
  int cnt = 0;
  int ca = n - 2;
  for (int i = dfw.size() - 1; i >= 0; i--) {
    if (dfw[i] >= ca) {
      ++cnt;
      --ca;
    } else
      break;
  }
  cout << cnt;
  return 0;
}
