#include <bits/stdc++.h>
using namespace std;
int tag[300005];
int seq[300005];
vector<int> p[300005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) tag[i] = 1;
  for (int i = 1; i <= n; i++) scanf("%d", seq + i);
  tag[seq[n]] = 0;
  memset(p, 0, sizeof p);
  int id = seq[n];
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    p[u].push_back(v);
    p[v].push_back(u);
    if (id == u) tag[v] = 0;
    if (id == v) tag[u] = 0;
  }
  int cnt = 0;
  for (int i = n - 1; i >= 1; i--) {
    if (tag[seq[i]] == 1) {
      tag[seq[i]] = -1;
      cnt++;
    } else if (tag[seq[i]] == 0) {
      int cnt2 = 0;
      for (int to : p[seq[i]])
        if (tag[to] == -1) cnt2++;
      if (cnt != cnt2) {
        tag[seq[i]] = -1;
        cnt++;
      }
    }
  }
  cout << n - 1 - cnt << endl;
}
