#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<long long> primeFact(long long n) {
  vector<long long> ans;
  for (long long t = 2; t <= sqrt(n); t++) {
    if (n % t == 0) {
      ans.push_back(t);
      while (n % t == 0) {
        n = n / t;
      }
    }
  }
  if (n > 2) ans.push_back(n);
  return ans;
}
vector<long long> fact(long long n) {
  vector<long long> ans;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (i * i == n) {
        ans.push_back(i);
      } else {
        ans.push_back(i);
        ans.push_back(n / i);
      }
    }
  }
  return ans;
}
long long powerr(long long base, long long exp, long long mod) {
  if (exp == 0) return 1;
  long long t = powerr(base, exp / 2, mod) % mod;
  if (exp % 2 == 0) {
    return (t % mod * t % mod) % mod;
  } else {
    return (t % mod * t % mod * base % mod) % mod;
  }
}
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int32_t main() {
  fastio();
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  reverse(a.begin(), a.end());
  long long p, q;
  vector<unordered_set<long long> > graph(n + 1);
  for (long long i = 0; i < m; i++) {
    cin >> p >> q;
    graph[q].insert(p);
  }
  long long t = 0;
  long long ans = 0;
  unordered_set<long long> s1, s2;
  for (auto i : graph[a[t]]) {
    s1.insert(i);
  }
  t++;
  for (long long i = t; i < n; i++) {
    if (s1.find(a[i]) != s1.end()) {
      ans++;
    }
    s2.clear();
    for (auto j : graph[a[i]]) {
      if (s1.find(j) != s1.end()) {
        s2.insert(j);
      }
    }
    s1 = s2;
  }
  cout << ans << "\n";
  return 0;
}
