#include <bits/stdc++.h>
using namespace std;
void InputSetup() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  int n, m;
  cin >> n >> m;
  int p[n], pos = n - 1;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
  }
  vector<set<int>> move(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    move[--u].insert(--v);
  }
  int r = -1;
  while (pos > 0) {
    if (move[p[pos - 1]].find(p[pos]) != move[p[pos - 1]].end()) {
      swap(p[pos], p[pos - 1]);
      --pos;
      continue;
    }
    int x = pos - 1;
    bool moved = 0;
    while (x > r + 1) {
      if (move[p[x - 1]].find(p[x]) != move[p[x - 1]].end()) {
        moved = 1;
        swap(p[x], p[x - 1]);
        --x;
      } else
        break;
    }
    if (!moved) break;
    r = x;
  }
  cout << n - 1 - pos;
}
int main(void) {
  InputSetup();
  for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);
       blockTime.second;
       fprintf(stderr, "%s: %lld ms\n", "Main",
               1LL * chrono::duration_cast<chrono::milliseconds>(
                         chrono::high_resolution_clock::now() - blockTime.first)
                         .count()),
            fflush(stderr), blockTime.second = false)
    solve();
}
