#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> pupils(n), pos(n);
  for (int i = 0; i < n; ++i) {
    cin >> pupils[i];
    --pupils[i];
    pos[pupils[i]] = i;
  }
  vector<int> cntr(n, 0);
  set<int> ds;
  int a, b;
  while (m--) {
    cin >> a >> b;
    --a, --b;
    if (b == pupils.back()) {
      ds.insert(a);
    }
    if (pos[b] > pos[a]) {
      ++cntr[a];
    }
  }
  int sol = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (ds.find(pupils[i]) != ds.end()) {
      if (cntr[pupils[i]] >= n - 1 - i - sol) {
        ++sol;
      } else {
        break;
      }
    }
  }
  cout << sol << "\n";
  return 0;
}
