#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 3e5 + 69;
int a[MAXN];
unordered_map<int, int> g[MAXN];
vector<pair<int, int>> q;
int p[MAXN];
int n, m;
bool check(int l, int r) {
  int x = a[l];
  for (int j = l + 1; j <= r; ++j) {
    if (!g[a[j]][a[j - 1]]) {
      return 0;
    }
    swap(a[j], a[j - 1]);
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i]--;
    p[a[i]] = i;
  }
  for (int i = 0; i < m; ++i) {
    int fr, to;
    cin >> fr >> to;
    g[to - 1][fr - 1] = 1;
  }
  int x = a[n - 1];
  int index = n - 1;
  int ans = 0;
  while (1) {
    int mem = index;
    while (index >= 0 && !g[x][a[index]]) {
      index--;
    }
    index = mem - 1;
    if (index < 0) {
      break;
    }
    if (check(index, mem)) {
      ans++;
    } else {
      break;
    }
  }
  cout << ans;
  return 0;
}
