#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  ;
  set<pair<long long, long long> > q;
  set<long long> q1;
  for (long long i = 0; i <= m - 1; i++) {
    long long l, r;
    cin >> l >> r;
    q.insert({r, l});
    if (r == arr[n - 1]) q1.insert(l);
  }
  map<long long, long long> q2;
  for (long long i = 0; i < n; i++) {
    if (q1.find(arr[i]) != q1.end()) q2[i] = arr[i];
  }
  long long i = n - 1;
  long long ans = 0;
  while (q2.size()) {
    auto x = *q2.rbegin();
    bool f = 1;
    for (long long k = i; k > x.first; k--) {
      if (q.find({arr[i], arr[x.first]}) == q.end()) f = 0;
    }
    vector<long long> xx1;
    for (long long k = i; k > x.first; k--) xx1.push_back(arr[k]);
    long long cc1 = 0;
    for (long long k = i - 1; k >= x.first; k--) {
      arr[k] = xx1[cc1];
      cc1++;
    }
    if (!f) break;
    i--;
    ans++;
    pair<long long, long long> it = *q2.rbegin();
    q2.erase(it.first);
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) solve();
}
