#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize 03
#pragma GCC optimize("unroll-loops")
using namespace std;
long long gcd(long long a, long long b) { return (a == 0) ? b : gcd(b % a, a); }
long long cnt1(long long x) {
  long long cnt = 0;
  while (x > 0) x &= x - 1, cnt++;
  return cnt;
}
long long fact(long long n) { return n == 0 ? 1LL : n * fact(n - 1); }
long long fact(long long n, long long p) {
  return n == 0 ? 1LL : n * fact(n - 1) % p;
}
long long cnk(long long n, long long k) {
  return n == 1 || k == 1 ? 1 : cnk(n - 1, k) + cnk(n - 1, k - 1);
}
long long pow(long long a, long long n, long long p) {
  if (n == 0) return 1;
  long long t = pow(a, n >> 1, p);
  return t * t % p * (n & 1 ? a : 1) % p;
}
long long back(long long x, long long p) { return pow(x, p - 2, p); }
long long cnk(long long n, long long k, long long p) {
  return fact(n, p) * back(fact(k, p), p) % p * back(fact(n - k, p), p) % p;
}
template <class T>
istream &operator>>(istream &stream, vector<T> &v) {
  for (long long i = 0; i < (long long)v.size(); i++) stream >> v[i];
  return stream;
}
template <class T>
ostream &operator<<(ostream &stream, vector<T> v) {
  for (long long i = 0; i < (long long)v.size(); i++) stream << v[i] << ' ';
  stream << '\n';
  return stream;
}
template <class A, class B>
istream &operator>>(istream &stream, pair<A, B> &p) {
  return stream >> p.first >> p.second;
}
const long long N = 3e+5 + 10;
set<long long> gr[N];
signed main() {
  srand(time(0));
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  cin >> a;
  set<long long> good;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    gr[x].insert(y);
    if (y == a.back()) good.insert(x);
  }
  long long need = a.back();
  for (long long i = 0; i < n; i++) {
    long long j = i;
    if (good.count(a[j]) == 0) {
      while (j > 0 && gr[a[j - 1]].count(a[j])) {
        swap(a[j], a[j - 1]);
        j--;
      }
    }
  }
  cout << n - 1 - (find(a.begin(), a.end(), need) - a.begin());
}
