#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int n, m, d[510000], pos[510000], ans, x, y, vv, pp;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &d[i]);
    pos[d[i]] = i;
  }
  for (int i = (1); i <= (m); i++) {
    scanf("%d%d", &x, &y);
    v.push_back(make_pair(x, y));
  }
  pp = d[n];
  vv = 1;
  while (vv == 1 && v.size() > 0) {
    vv = 0;
    for (vector<pair<int, int> >::iterator it = v.begin(); it != v.end(); it++)
      if (pos[it->first] + 1 == pos[it->second]) {
        int t = d[pos[it->first]];
        d[pos[it->first]] = d[pos[it->second]];
        d[pos[it->second]] = t;
        t = pos[it->first];
        pos[it->first] = pos[it->second];
        pos[it->second] = t;
        v.erase(it, it + 1);
        vv = 1;
        break;
      }
    ans = max(ans, n - pos[pp]);
  }
  printf("%d\n", ans);
  return 0;
}
