#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int maxn = 3e5 + 10;
vector<int> G[maxn];
int a[maxn], b[maxn];
set<int> se[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[a[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[b[x]].push_back(b[y]);
    G[b[y]].push_back(b[x]);
    se[b[x]].insert(b[y]);
    se[b[y]].insert(b[x]);
  }
  sort(G[n].begin(), G[n].end());
  int cnt = 0;
  int pos = n;
  for (int i = 0; i < G[n].size(); i++) {
    int id = G[n][i];
    int flag = 1;
    for (int j = id + 1; j < pos; j++) {
      if (!se[id].count(j)) {
        flag = 0;
        break;
      }
    }
    pos--;
    cnt++;
  }
  printf("%d\n", cnt);
  return 0;
}
