#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <class T>
int sgn(T x) {
  return x > 0 ? 1 : (x < 0 ? -1 : 0);
}
const double pi = acos(-1.);
const int N = 3e5 + 20;
const int inf = 1e9 + 7;
int n, m;
int pos[N];
int a[N];
int was[N];
set<int> s[N];
bool comp(int x, int y) { return pos[x] < pos[y]; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
    pos[a[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    s[y].insert(x);
  }
  int cur = a[n - 1];
  vector<int> q;
  for (int i = 0; i < n; i++)
    if (a[i] != cur && s[cur].count(a[i]) == 0)
      q.push_back(a[i]), was[a[i]] = 1;
  if (!((int)q.size())) {
    cout << n - 1;
    return 0;
  }
  sort((q).begin(), (q).end(), comp);
  for (auto x : q) {
    while (pos[x] && !was[a[pos[x] - 1]] && s[x].count(a[pos[x] - 1])) {
      swap(a[pos[x]], a[pos[x] - 1]);
      pos[a[pos[x] - 1]] = pos[x];
      pos[x]--;
    }
  }
  cout << n - pos[q.back()] - 2;
}
