#include <bits/stdc++.h>
using namespace std;
int order[300010];
set<int> canChange[300010];
int main(void) {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> order[i];
  set<int> canLast;
  set<int> canNewLast;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    canChange[a].insert(b);
    canChange[b].insert(a);
  }
  for (int i = 0; i < N; i++) {
    int cur = order[i];
    canNewLast.clear();
    for (int j : canLast) {
      if (canChange[cur].find(j) != canChange[cur].end()) canNewLast.insert(j);
    }
    canLast = canNewLast;
    canLast.insert(order[i]);
  }
  cout << canLast.size() - 1 << endl;
  return 0;
}
