#include <bits/stdc++.h>
using namespace std;
void execution();
int main() {
  ios_base::sync_with_stdio(0);
  execution();
  return 0;
}
set<int> g[(int)3e5 + 15];
pair<int, int> bam[(int)3e5 + 15];
void execution() {
  int n, m, nas, ans = 0;
  cin >> n >> m;
  vector<int> in(n);
  cin >> in[0];
  bam[in[0]].first = 3e5 + 13;
  for (int i = 1; i < n; i++) {
    cin >> in[i];
    bam[in[i - 1]].second = in[i];
    bam[in[i]].first = in[i - 1];
  }
  nas = in.back();
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].insert(v);
  }
  for (int i = n - 1; i >= 0; i--) {
    while (g[in[i]].count(bam[in[i]].second) && bam[in[i]].second != nas) {
      int now = in[i], nxt = bam[in[i]].second, prv = bam[in[i]].first,
          nxtsn = bam[nxt].second;
      bam[prv].second = nxt;
      bam[nxt].first = prv;
      bam[now].first = prv;
      bam[now].second = nxtsn;
      bam[nxt].second = now;
      bam[nxtsn].first = now;
    }
    if (bam[in[i]].second == nas && g[in[i]].count(nas)) {
      int prv = bam[in[i]].first;
      bam[nas].first = prv;
      bam[prv].second = nas;
      ans++;
    }
  }
  cout << ans;
}
