#include <bits/stdc++.h>
using namespace std;
int order[300010];
int canswap[300010];
set<int> canChange[300010];
int main(void) {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> order[i];
  int place = N - 1;
  int nas = order[place];
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    canChange[a].insert(b);
    canChange[b].insert(a);
    if (a == nas) canswap[b] = 1;
    if (b == nas) canswap[a] = 1;
  }
  while (true) {
    if (!place) break;
    int front = order[place - 1];
    if (canswap[front])
      order[--place] = nas;
    else {
      int flag = 0;
      int idx = place - 1;
      while (idx) {
        int ffront = order[idx - 1];
        if (canChange[front].find(ffront) != canChange[front].end()) {
          idx--;
          swap(order[idx], order[idx + 1]);
          if (canswap[ffront]) flag = 1;
        } else
          break;
      }
      if (!flag) break;
    }
  }
  cout << N - 1 - place << endl;
  return 0;
}
