#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 140;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> p(n);
  for (long long i = 0; i < n; i++) {
    cin >> p[i];
  }
  long long man = p[n - 1];
  unordered_map<long long, long long> has;
  vector<vector<long long>> g(N);
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    if (y == man) {
      has[x]++;
    }
  }
  unordered_map<long long, long long> mp;
  long long ans = 0;
  for (long long i = n - 2; i >= 0; i--) {
    long long cur = p[i], s2 = 0;
    for (auto x : g[cur]) {
      if (mp.find(x) != mp.end()) {
        s2++;
      }
    }
    if (s2 == mp.size() && (has.find(cur) != has.end())) {
      mp.clear();
      ans++;
    }
    mp[cur]++;
  }
  cout << ans << '\n';
  return 0;
}
