#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 5;
struct Edge {
  int u, v;
};
map<pair<int, int>, int> mp;
int arr[MAX];
inline void _swap(int &u, int &v) {
  int temp = u;
  u = v, v = temp;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
  }
  for (int i = 0, u, v; i < m; ++i) {
    cin >> u >> v;
    mp[make_pair(u, v)] = 1;
  }
  int lastpos = n;
  for (int i = n - 1; i >= 1; --i) {
    int x = arr[i];
    int xpos = i;
    if (!mp[make_pair(x, arr[lastpos])]) continue;
    while (xpos + 1 < lastpos && mp[make_pair(x, arr[xpos + 1])]) {
      _swap(arr[xpos], arr[xpos + 1]);
      ++xpos;
    }
    if (xpos == lastpos - 1) --lastpos;
  }
  printf("%d\n", n - lastpos);
  return 0;
}
