#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, MOD = INF + 7;
int power(int a, int b) {
  return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1));
}
const int N = 3e5 + 20, M = 1e3 + 2;
vector<int> g[N];
bool visited[N];
int p[N], a[N];
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    a[p[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    int v, u;
    cin >> v >> u;
    g[v].push_back(u);
  }
  int ans = 0;
  for (int i = n - 1, cnt = 0; i >= 1; i--, cnt = 0) {
    for (int u : g[i])
      if (i < a[u] && !visited[u]) cnt++;
    if (cnt == n - i - ans) {
      ans++;
      visited[p[i]] = true;
    }
  }
  cout << ans << "\n";
  return 0;
}
