#include <bits/stdc++.h>
using namespace std;
int n, m, cnnt, slr;
int a[300005], pos[300005];
bool vis[500005];
struct node {
  int id, x;
};
vector<node> vec[300005];
bool cmp1(node a, node b) { return pos[a.x] > pos[b.x]; }
bool cmp2(node a, node b) { return pos[a.x] < pos[b.x]; }
int main() {
  scanf("%d%d", &n, &m);
  cnnt = n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
  }
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    vec[l].push_back((node){i, r});
    vec[r].push_back((node){i, l});
  }
  sort(vec[a[n]].begin(), vec[a[n]].end(), cmp1);
  int tmp = a[n];
  for (int i = 0; i < vec[tmp].size(); ++i) {
    int c = vec[tmp][i].x;
    sort(vec[c].begin(), vec[c].end(), cmp2);
    for (int j = 0; j < vec[c].size(); ++j) {
      if (vis[vec[c][j].id]) continue;
      int tp = vec[c][j].x;
      if (tp == tmp) slr = c;
      if (pos[tp] == pos[c] + 1) {
        swap(a[pos[tp]], a[pos[c]]);
        swap(pos[tp], pos[c]);
      }
    }
  }
  if (pos[slr] == pos[tmp] + 1) {
    int cnt = 0;
    for (int i = 0; i < vec[slr].size(); ++i) {
      if (vec[slr][i].x == tmp) cnt ^= 1;
    }
    if (!cnt) ++pos[tmp];
  }
  printf("%d\n", n - pos[tmp]);
  return 0;
}
