#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcount(s);
}
template <class T>
inline T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long n, m, a[300005], res, dau, nas, vt[300005];
map<pair<long long, long long>, bool> ok;
vector<long long> v, lu;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1, _b = n; i <= _b; i++) {
    cin >> a[i];
    vt[a[i]] = i;
  }
  nas = a[n];
  for (long long i = 1, _b = m; i <= _b; i++) {
    long long l, r;
    cin >> l >> r;
    ok[{l, r}] = true;
    if (r == nas) v.push_back(vt[l]);
  }
  long long now = n;
  while (ok[{a[now - 1], a[now]}] && now > 1) {
    swap(a[now], a[now - 1]);
    now--;
  }
  if (now == 1) {
    cout << n - 1;
    return 0;
  }
  sort(v.begin(), v.end());
  for (long long i = v.size() - 1, _b = 0; i >= _b; i--) {
    long long s = v[i];
    if (s >= now) continue;
    if (s + 1 == now) {
      now = s;
      continue;
    }
    if (!lu.size()) {
      for (long long j = s + 1, _b = now; j < _b; j++) {
        lu.push_back(a[j]);
      }
    }
    for (auto z : lu) {
      if (!ok[{a[s], z}]) {
        cout << n - now;
        exit(0);
      }
    }
    swap(a[s], a[now - 1]);
    now--;
  }
  cout << n - now;
  return 0;
}
