#include <bits/stdc++.h>
using namespace std;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const long long int Inf = 1LL << 62;
set<int> G[Max];
int p[Max];
int main() {
  int n, m, u, v, cnt = 0;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  while (m--) {
    scanf("%d %d", &u, &v);
    G[u].insert(v);
  }
  for (int i = n - 1; i >= 1; i--) {
    if (G[p[i]].find(p[i + 1]) == G[p[i]].end()) {
      if (G[p[i - 1]].find(p[i]) != G[p[i - 1]].end()) {
        if (G[p[i - 1]].find(p[i + 1]) != G[p[i - 1]].end()) {
          swap(p[i], p[i - 1]);
        }
      }
    }
    if (G[p[i]].find(p[i + 1]) != G[p[i]].end()) {
      cnt += 1;
    } else {
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}
