#include <bits/stdc++.h>
using namespace std;
vector<int> v[300000];
char ap[300000];
int p[300000];
char ct[300000];
int main() {
  int n, m, i, j, x, y;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    v[x].push_back(y);
  }
  int r = 0;
  char bun;
  for (i = n - 2; i >= 0; i--) {
    if (v[p[i]].size() >= n - i - 1) {
      for (j = 0; j < v[p[i]].size(); j++) ap[v[p[i]][j]] = 1;
      bun = 1;
      for (j = i + 1; j < n && bun; j++)
        if (!ct[p[j]] && !ap[p[j]]) bun = 0;
      r += bun;
      if (bun) ct[p[i]] = 1;
      for (j = 0; j < v[p[i]].size(); j++) ap[v[p[i]][j]] = 0;
    }
  }
  printf("%d", r);
  return 0;
}
