#include <bits/stdc++.h>
using namespace std;
int a[300100];
set<int> s[500100];
void solve(int i) {
  if (i <= 0) return;
  while (i && s[a[i]].count(a[i - 1])) {
    s[a[i]].erase(a[i - 1]);
    swap(a[i], a[i - 1]);
    i--;
  }
  solve(i - 1);
  while (i && s[a[i]].count(a[i - 1])) {
    s[a[i]].erase(a[i - 1]);
    swap(a[i], a[i - 1]);
    i--;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    s[y].insert(x);
  }
  int goal = a[n - 1], pos;
  solve(n - 1);
  for (int i = 0; i < n; i++) {
    if (a[i] == goal) {
      pos = i;
      break;
    }
  }
  cout << n - pos - 1;
  return 0;
}
