#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(int num, int idx) { return num ^ (1 << idx); }
void FS() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
const int N = 500009;
int p[N], pos[N], vis[N], cnt[N];
vector<vector<int> > v(N);
vector<pair<int, int> > v1;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    pos[p[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    int U, V;
    cin >> U >> V;
    v[V].push_back(U);
  }
  int visid = 0, previsid;
  for (int i = 2; i <= n; i++) {
    int no = p[i];
    previsid = visid;
    visid++;
    for (int j = 0; j < ((int)(v[no]).size()); j++) {
      int nw = v[no][j];
      if ((pos[nw] != i - 1) && (vis[nw] != previsid || pos[nw] > i)) continue;
      vis[nw] = visid;
      cnt[nw]++;
    }
    vis[no] = visid;
  }
  for (int i = 1; i < n; i++) {
    int no = p[i];
    v1.push_back(make_pair(cnt[no], no));
  }
  sort(((v1).rbegin()), ((v1).rend()));
  int ans = 0;
  int mypos = n;
  for (int i = 0; i < ((int)(v1).size()); i++) {
    int c = v1[i].first;
    int no = v1[i].second;
    if (mypos <= pos[no]) continue;
    int d = (mypos - pos[no]);
    if (c >= d) {
      ans++;
      mypos--;
    } else
      break;
  }
  cout << ans << endl;
}
