#include <bits/stdc++.h>
using namespace std;
const int N = 550000;
unordered_map<int, int> H[N];
vector<int> adj[N];
int p[N], pos[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> p[i], pos[p[i]] = i;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    H[u][v] = 1;
  }
  int ans = 0;
  for (int x : adj[p[n]]) {
    int cur = pos[x];
    int val = 1;
    for (int i = cur + 1; i < n; i++) {
      if (!H[x].count(p[i])) {
        val = 0;
        break;
      }
    }
    ans += val;
  }
  cout << ans << endl;
  return 0;
}
