#include <bits/stdc++.h>
using namespace std;
const int _max = 3e5 + 10;
int n, m;
int p[_max], mp[_max];
vector<int> vix[_max];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", p + i);
    mp[p[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    vix[mp[u]].push_back(mp[v]);
  }
  int ans = 0;
  for (int i = n - 1; i > 0; i--) {
    if (vix[i].size() == 0) continue;
    sort(vix[i].begin(), vix[i].end());
    int pop = vix[i][vix[i].size() - 1], cmax = i;
    if (pop != n) continue;
    for (int j = 0; j < vix[i].size() - 1; j++)
      if (cmax + 1 == vix[i][j]) cmax++;
    if (i + ans + 1 == n || cmax + ans + 1 == n) ans++;
  }
  printf("%d", ans);
  return 0;
}
