#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int MAXM = 5e5 + 5;
int n, m;
vector<int> p;
vector<int> v;
vector<int> adj[MAXN];
int moves = 0;
int cur = -1;
int num = 0;
int best = INT_MAX;
void shift(int idx, int ahead) {
  if (v[idx] == num) best = min(best, idx);
  if (idx == 0) return;
  if (v[idx - 1] == ahead) {
    swap(v[idx - 1], v[idx]);
  } else {
    for (int i : adj[v[idx - 1]]) {
      shift(idx - 1, i);
      if (v[idx - 1] == ahead) {
        swap(v[idx - 1], v[idx]);
      }
      if (v[idx - 1] == num) {
        for (int i : adj[num]) shift(idx - 1, i);
      } else {
        return;
      }
    }
  }
  if (v[idx - 1] == num) {
    for (int i : adj[num]) shift(idx - 1, i);
  } else {
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    p.push_back(k);
    v.push_back(k);
  }
  num = p[n - 1];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[v].push_back(u);
  }
  best = n - 1;
  for (int i : adj[num]) {
    v = p;
    shift(n - 1, i);
  }
  cout << n - 1 - best;
  return 0;
}
