#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 100100, MAXM = 5 * 100100;
int n, m, p[MAXN], rp[MAXN];
vector<int> x[MAXN];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]), rp[p[i]] = i;
  for (int i = 1, u, v; i <= m; ++i)
    scanf("%d %d", &u, &v), x[rp[u]].push_back(rp[v]);
  for (int i = 1; i <= n; ++i) sort(x[i].begin(), x[i].end());
  int pos = n;
  for (int i = n - 1; i >= 1; --i) {
    if (x[i].size() < n - i) continue;
    bool flg = true;
    for (int j = i + 1; j <= n; ++j)
      if (p[j] != 0 && x[i][j - i - 1] != j) {
        flg = false;
        break;
      }
    if (!flg) continue;
    p[i] = 0;
    pos--;
  }
  printf("%d\n", n - pos);
}
