#include <bits/stdc++.h>
#pragma comment(linker, "/stack:256000000")
using namespace std;
mt19937_64 gen(time(NULL));
int const maxn = 3e5 + 5;
long long idx[maxn];
vector<long long> g[maxn];
bool used[maxn];
long long comp[maxn];
long long k = 1;
void dfs(long long u) {
  comp[u] = k;
  for (long long v : g[u]) {
    if (comp[v]) continue;
    dfs(v);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long m;
  cin >> m;
  for (long long i = 1; i <= n; i++) {
    long long t;
    cin >> t;
    idx[t] = i;
  }
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    if (idx[u] > idx[v])
      continue;
    else {
      u = idx[u];
      v = idx[v];
      g[u].push_back(v);
      g[v].push_back(u);
    }
  }
  dfs(n);
  long long kek = 0;
  for (long long i = n; i >= 1; i--) {
    if (!comp[i]) {
      kek = i;
      break;
    }
  }
  kek++;
  bool f = false;
  for (long long i = kek; i <= n; i++) {
    for (long long v : g[i]) {
      if (v >= kek && v == i - 1) {
        f = true;
      }
    }
  }
  long long ans = 0;
  for (long long v : g[n]) {
    if (v >= kek) {
      ans++;
    }
  }
  if (f)
    cout << ans << endl;
  else
    cout << 0;
  return 0;
}
