#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long takemod(long long a) { return ((a % mod) + mod) % mod; }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long fast_exp(long long base, long long expo) {
  long long res = 1;
  while (expo > 0) {
    if (expo & 1) res = (res * base) % mod;
    base = (base * base) % mod;
    expo >>= 1;
  }
  return res;
}
long long modinv(long long a) { return takemod(fast_exp(takemod(a), mod - 2)); }
multiset<long long> graph[300001];
long long n, m;
long long arrangement[300001];
long long currpos;
long long arr1[300001];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  memset(arr1, 0, sizeof(arr1));
  cin >> n >> m;
  for (long long i = (0); i < (n); i++) {
    long long a;
    cin >> a;
    arrangement[i] = a;
  }
  for (long long i = (0); i < (m); i++) {
    long long a, b;
    cin >> a >> b;
    graph[a].insert(b);
    if (b == arrangement[n - 1]) arr1[a] = 1;
  }
  multiset<long long> ans;
  for (long long i = (n - 1) - 1; i >= (0); i--) {
    if (arr1[arrangement[i]] == 1) {
      long long flag = 0;
      multiset<long long, greater<long long>>::iterator index1;
      multiset<long long, greater<long long>>::iterator index2;
      index1 = graph[arrangement[i]].begin();
      index2 = ans.begin();
      while (index1 != graph[arrangement[i]].end() and index2 != ans.end()) {
        if (*index1 == *index2) {
          index1++;
          index2++;
        } else if (*index1 > *index2) {
          flag = 1;
          break;
        } else
          index2++;
      }
      if (index2 != ans.end()) flag = 1;
      if (flag == 1) ans.insert(arrangement[i]);
    } else
      ans.insert(arrangement[i]);
  }
  cout << n - ans.size() - 1 << "\n";
  return 0;
}
