#include <bits/stdc++.h>
using namespace std;
int q[300000];
int b[300000];
unordered_set<int> g[300000];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    q[t - 1] = i;
    b[i] = i + 1;
  }
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    g[q[l - 1]].insert(q[r - 1]);
  }
  int cnt = 0;
  for (int i = n - 2; i >= 0; i--) {
    bool yes = true;
    for (int j = i + 1; j < n; j = b[j]) {
      if (g[i].find(j) == g[i].end()) {
        yes = false;
        break;
      }
    }
    if (yes) {
      if (i > 0) b[i - 1] = b[i];
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
