#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[300005], b[300005];
vector<int> e[300005];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < 300005; i++) e[i].clear();
    for (int i = 1; i <= n; i++) {
      scanf("%d", &b[i]);
      a[b[i]] = i;
    }
    for (int i = 1, x, y; i <= m; i++) {
      scanf("%d%d", &x, &y);
      if (a[y] > a[x]) e[x].push_back(y);
    }
    int ans = 0;
    int id = n;
    for (int i = n - 1; i >= 1; i--) {
      if (e[b[i]].size() >= id - i) {
        ans++;
        id--;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
